Last active
March 30, 2020 06:38
-
-
Save martanto/bb00bb1e5b3b62245647e2906bb212f9 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 | |
class User | |
{ | |
public $firstName = 'Bob'; | |
protected $attributes = [ | |
'firstName' => 'Anto', | |
]; | |
public function __get($key) | |
{ | |
return $this->attributes[$key]; | |
} | |
} | |
$normalUser = new User; | |
$normalUser->firstName; |
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 MyClass | |
{ | |
public function __construct() {} | |
public function __destruct() {} | |
public function __call() {} | |
public function __callStatic() {} | |
public function __get() {} | |
public function __set() {} | |
public function __isset() {} | |
public function __unset() {} | |
public function __sleep() {} | |
public function __wakeup() {} | |
public function __toString() {} | |
public function __invoke() {} | |
public function __set_state() {} | |
public function __clone() {} | |
public function __debuginfo() {} | |
} |
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 User | |
{ | |
public $attributes = [ | |
'firstName' => 'Anto', | |
]; | |
public function __set($key, $value) | |
{ | |
$this->attributes[$key] = $value; | |
} | |
} | |
$normalUser = new User; | |
$normalUser->firstName = 'Martanto'; | |
$normalUser->attributes['firstName']; // Will return 'Martanto' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment