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
| =========================================== | |
| Namespace: 'PHPTest' | |
| =========================================== | |
| Array | |
| ( | |
| [name] => PHPTest | |
| [internal] => | |
| [user-defined] => 1 | |
| [parent] => ReflectionNamespace Object | |
| ( |
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 | |
| final immutable class Currency {} | |
| final immutable class Money { | |
| public $amount; | |
| public $currency; | |
| public function __construct(float $amount, Currency $currency) { | |
| $this->amount = $amount; | |
| $this->currency = $currency; | |
| } |
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 | |
| immutable class Currency | |
| { | |
| /** @var string */ | |
| public $code; // this will change to readonly after constructor execution | |
| /** @var string */ | |
| public $name; // this will change to readonly after constructor execution | |
| /** @var int */ | |
| public $fractionDigits; |
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 | |
| class Article { | |
| private final $comments = []; | |
| public function addComment(Comment $comment) { | |
| $this->comments[] = $comment; | |
| } | |
| public function clearComments() { | |
| $this->comments = []; | |
| } | |
| } |
NewerOlder