3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Foo { } class Bar { } $foo = new Foo(); $foo = change_class($foo, 'Bar'); var_dump($foo); 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 5.0.0 - 7.1.0
object(Bar)#2 (0) { }
Output for 4.3.0 - 4.4.9
object(bar)(0) { }