Last active
June 8, 2016 16:28
-
-
Save brzuchal/8411a9b299f521e0186a2077be8f5321 to your computer and use it in GitHub Desktop.
PHP package-private class members
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| package MyVendor\MyLibrary // acts same as `namespace` but changes all classes into package-private | |
| { | |
| namespace MyInternalStuff // cause current namespace would be MyVendor\MyLibrary\MyInternalStuff | |
| { | |
| class MyNonPublicWidget // class name would be MyVendor\MyLibrary\MyInternalStuff\MyNonPublicWidget | |
| { | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| package MyVendor\MyLibrary | |
| { | |
| namespace // missing name cause class ns woul be MyVendor\MyLibrary | |
| { | |
| public class PublicApi // any package class need to be public prefixed for visibility in lower level namespaces (out of package namespace) | |
| { | |
| private $widget; | |
| public function __construct() | |
| { | |
| $this->widget = new MyInternalStuff\MyNonPublicWidget(); | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| package MyVendor\MyLibrary; // acts same as `namespace` but changes all classes into package-private | |
| public class PublicApi // as of we are in package we need to set public visibility in packag lower namespaces | |
| { | |
| private $widget; | |
| public function __construct() | |
| { | |
| $this->widget = new MyInternalStuff\MyNonPublicWidget(); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
namespacekeyword if not providing any name insidepackagedeclaration is optional, so provided with missing name has no effect.