fork download
  1. <?php
  2.  
  3. class MyClass {
  4. public $properties = [];
  5.  
  6. public function __construct($args){
  7. $this->properties = $args;
  8. }
  9.  
  10. public function __get($name) {
  11. if (array_key_exists($name, $this->properties)) {
  12. return $this->properties[$name];
  13. }
  14. return null;
  15. }
  16. }
  17.  
  18. $obj = new MyClass(["key1" => "value1", "key2" => "value2"]);
  19.  
  20. var_dump($obj->key1);
  21. var_dump($obj->key2);
  22. var_dump($obj->key3);
Success #stdin #stdout 0.02s 24352KB
stdin
Standard input is empty
stdout
string(6) "value1"
string(6) "value2"
NULL