<?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);