-
-
Save DavidMikeSimon/8738363 to your computer and use it in GitHub Desktop.
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 | |
| trait Methods | |
| { | |
| public function __call($name, $args) | |
| { | |
| if (property_exists($this, $name)) { | |
| return $this->$name; | |
| } | |
| if (get_parent_class($this)) { | |
| return parent::__call($name, $args); | |
| } | |
| return null; | |
| } | |
| } | |
| class Person | |
| { | |
| use Methods; | |
| private $pPrivate = 'pPrivate'; | |
| protected $pProtected = 'pProtected'; | |
| public $pPublic = 'pPublic'; | |
| } | |
| class Salesman extends Person | |
| { | |
| use Methods; | |
| private $sPrivate = 'sPrivate'; | |
| protected $sProtected = 'sProtected'; | |
| public $sPublic = 'sPublic'; | |
| } | |
| $dude = new Salesman(); | |
| var_dump($dude->sPublic()); | |
| var_dump($dude->sProtected()); | |
| var_dump($dude->sPrivate()); | |
| var_dump($dude->pPublic()); | |
| var_dump($dude->pProtected()); | |
| var_dump($dude->pPrivate()); | |
| var_dump($dude->weirdthing()); # No such variable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment