3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // $a = new stdClass(); // $a->sum = function($a,$b){return $a + $b;}; // // var_dump($a->sum); // // echo ($a->sum)(3,5); // $b = (object)["sum" => function($a,$b){return $a + $b;}]; // var_dump(($b->sum)(1,2)); class A{ public $sum; function __construct(){ $this->sum = function($a, $b){ return $a + $b; }; } function __call($method,$args) { // var_dump($method,$args); return call_user_func_array($this->$method, $args); // var_dump($test,$this->$method); } } $a = new A(); var_dump($a->sum(1,2)); $a->sub = function($a, $b){ return $a- $b; }; var_dump($a->sub(10,5)); var_dump($a->multiply(10,5));
based on lGPEU
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.3.0alpha1
int(3) int(5) Notice: Undefined property: A::$multiply in /in/1veYm on line 26 Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /in/1veYm on line 26 NULL
Output for hhvm-3.15.4
int(3) int(5) Notice: Undefined property: A::$multiply in /in/1veYm on line 26 Warning: Invalid argument: function: not string, closure, or array in /in/1veYm on line 26 NULL