3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function sing() { var_dump('Do re mi!'); } public function dance() { var_dump('Cha cha cha!'); } } function gimmeFoo(Foo $foo) { $foo->sing(); $foo->dance(); } $gimmeWhat = new ReflectionFunction('gimmeFoo'); $class = $gimmeWhat->getParameters()[0]->getClass(); $methods = $class->getMethods(); $evil = " class Fake extends $class->name { public function idoeverything() { var_dump('Just kidding!'); } "; foreach ($methods as $method) { $evil .= "public function $method->name() {\$this->idoeverything();}"; } $evil .= "}"; eval($evil); $fake = new Fake; gimmeFoo($fake);

preferences:
43.05 ms | 402 KiB | 5 Q