Skip to content

Instantly share code, notes, and snippets.

@nulpatrol
Created March 11, 2018 18:16
Show Gist options
  • Save nulpatrol/3734e8c3cd6e90f9b8973d3049030eeb to your computer and use it in GitHub Desktop.
Save nulpatrol/3734e8c3cd6e90f9b8973d3049030eeb to your computer and use it in GitHub Desktop.
test.php
<?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