fork download
  1. <?php
  2.  
  3. class A
  4. {
  5. protected $data = ['preset' => []];
  6.  
  7. public function __call($name, $arguments)
  8. {
  9. var_dump('__call()');
  10.  
  11. if ( method_exists($this, $name) ) {
  12. call_user_func_array([$this, $name], $arguments);
  13. }
  14.  
  15. return $this;
  16. }
  17.  
  18. public function get()
  19. {
  20. $this->setPreset();
  21. return $this->data;
  22. }
  23.  
  24. protected function setPreset()
  25. {
  26. $this->data['preset'][] = 'foo';
  27. }
  28. }
  29.  
  30. $A = new A();
  31.  
  32. $data = $A->setPreset()
  33. ->get();
  34.  
  35. var_dump($data);
  36.  
Success #stdin #stdout 0.01s 82880KB
stdin
Standard input is empty
stdout
string(8) "__call()"
array(1) {
  ["preset"]=>
  array(2) {
    [0]=>
    string(3) "foo"
    [1]=>
    string(3) "foo"
  }
}