Created
March 11, 2018 18:16
-
-
Save nulpatrol/3734e8c3cd6e90f9b8973d3049030eeb to your computer and use it in GitHub Desktop.
test.php
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 Human { | |
| public $name; | |
| public $values = []; | |
| public $surname; | |
| public function __construct($name) | |
| { | |
| $this->name = $name; | |
| } | |
| public function __set($name, $value) | |
| { | |
| $this->values[$name] = $value; | |
| } | |
| public function __get($name) | |
| { | |
| return $this->values[$name]; | |
| } | |
| } | |
| $rost = new Human('Rost'); | |
| $rost->surname = 'Khaniukov'; // Оскільки поля surname немає, то викликається __set | |
| echo $rost->surname; // Ну а тут __get | |
| echo $rost->name; // Rost | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment