3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public $dummy1; public $dummy2; } class ErrorHandler { private $private = 'THIS IS PRIVATE'."\n"; function __construct() { set_error_handler( function ($errno, $errstr, $errfile, $errline) { $this->handleError($errno, $errstr, $errfile, $errline); } ); } private function handleError($errno, $errstr, $errfile, $errline, $errmodule = null) { echo __METHOD__. " dealing with error $errstr, $errfile:$errline\n"; // This attribute is no longer accessible in this object. Same for other // objects and their private attributes once we reach in this state. echo $this->private; echo "Never executed in PHP7.2; there is a fatal error in the line above\n"; } } function reproduceBug(Foo $f) { unset($f->dummy2); foreach ((new ReflectionObject($f))->getProperties() as $p) echo $p->getName() .' = '. $p->getValue($f) ."\n"; echo "This line is not reached in PHP7.2; but it is reached in PHP 7.0\n"; } $errorHandler = new ErrorHandler(); echo $x; # uncommenting this fixes it reproduceBug(new Foo);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
ErrorHandler::handleError dealing with error Undefined variable $x, /in/HWETd:46 THIS IS PRIVATE Never executed in PHP7.2; there is a fatal error in the line above dummy1 = ErrorHandler::handleError dealing with error Undefined property: Foo::$dummy2, /in/HWETd:39 THIS IS PRIVATE Never executed in PHP7.2; there is a fatal error in the line above dummy2 = This line is not reached in PHP7.2; but it is reached in PHP 7.0
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 ErrorHandler::handleError dealing with error Undefined variable $x, /in/HWETd:46 THIS IS PRIVATE Never executed in PHP7.2; there is a fatal error in the line above dummy1 = ErrorHandler::handleError dealing with error Undefined property: Foo::$dummy2, /in/HWETd:39 THIS IS PRIVATE Never executed in PHP7.2; there is a fatal error in the line above dummy2 = This line is not reached in PHP7.2; but it is reached in PHP 7.0
Output for 7.0.7 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
ErrorHandler::handleError dealing with error Undefined variable: x, /in/HWETd:46 THIS IS PRIVATE Never executed in PHP7.2; there is a fatal error in the line above dummy1 = ErrorHandler::handleError dealing with error Undefined property: Foo::$dummy2, /in/HWETd:39 THIS IS PRIVATE Never executed in PHP7.2; there is a fatal error in the line above dummy2 = This line is not reached in PHP7.2; but it is reached in PHP 7.0
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.6
ErrorHandler::handleError dealing with error Undefined variable: x, /in/HWETd:46 THIS IS PRIVATE Never executed in PHP7.2; there is a fatal error in the line above dummy1 = dummy2 = This line is not reached in PHP7.2; but it is reached in PHP 7.0

preferences:
195.51 ms | 402 KiB | 289 Q