@ 2015-10-29T16:21:05Z <?php
class SomeClass {
static function staticMethod(){
echo "SomeClass::staticMethod()";
}
}
class Dynamic extends stdClass{
public function __call($key,$params){
if(!isset($this->{$key}))
throw new Exception("Call to undefined method ".get_class($this)."::".$key."()");
call_user_func_array($$this->{$key},$params);
}
}
$dynamic = new Dynamic;
$dynamic->myMethod = "thatFunction";
$dynamic->hisMethod = array($dynamic,"aMethod");
$dynamic->newMethod = array("SomeClass","staticMethod");
$dynamic->anotherMethod = function(){
echo "Hey there";
};
echo("<pre>");
$dynamic->newMethod();
echo("</pre>");
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.19 , 8.3.0 - 8.3.7 <pre>
Fatal error: Uncaught Error: Object of class Dynamic could not be converted to string in /in/J39XV:13
Stack trace:
#0 /in/J39XV(26): Dynamic->__call('newMethod', Array)
#1 {main}
thrown in /in/J39XV on line 13
Process exited with code 255 . Output for 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 <pre>
Recoverable fatal error: Object of class Dynamic could not be converted to string in /in/J39XV on line 13
Process exited with code 255 . Output for 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.40 , 7.0.0 - 7.0.33 <pre>
Catchable fatal error: Object of class Dynamic could not be converted to string in /in/J39XV on line 13
Process exited with code 255 . preferences:dark mode live preview
239.49 ms | 402 KiB | 377 Q