3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Foo { function test() { echo 'foo test'; } } class Bar { function test() { echo 'bar test'; } } $foo = new Foo(); $foo = change_class($foo, 'Bar'); $foo->test(); function change_class($object, $new_class) { preg_match('~^O:[0-9]+:"[^"]+":(.+)$~', serialize($object), $matches); return unserialize(sprintf('O:%s:"%s":%s', strlen($new_class), $new_class, $matches[1])); }
Output for 4.3.0 - 7.1.0
bar test