fork download
  1. <?php
  2.  
  3. class A {
  4. public $_tst;
  5. public $_cb;
  6.  
  7. function __construct () {
  8.  
  9.  
  10. $this->_cb = function($x) {
  11. return 10;
  12. };
  13.  
  14. }
  15.  
  16. function __call($n, $v) {
  17. if ($n === 'cb') {
  18. return call_user_func($this->_cb, $v);
  19. }
  20. }
  21.  
  22. function __set($n, $v) {
  23. if ($n === 'tst') {
  24. $this->_tst = $this->cb($v);
  25. }
  26. if ($n === 'cb') {
  27. $this->_cb = $v;
  28. }
  29. }
  30.  
  31. function run() {
  32. echo $this->_tst . "\n";
  33. }
  34. }
  35.  
  36. $a = new A();
  37.  
  38. $a->tst = 30;
  39.  
  40. $a->run();
  41.  
  42. $a->cb = function() {return 50;};
  43.  
  44. $a->tst = 70;
  45.  
  46. $a->run();
Success #stdin #stdout 0.04s 23536KB
stdin
Standard input is empty
stdout
10
50