I'm getting a strange behavior with PHP 5.4 here. Suppose the following code:
class ExceptionDuringConstruction
{
public function __construct() {
echo '<br />construct before exception';
throw new Exception('construction failed');
echo '<br />construct after exception'; // unreachable, just checking
}
public function __destruct() {
echo '<br />destruct';
}
}
$reflection = new \ReflectionClass('ExceptionDuringConstruction');
$instance = $reflection->newInstance();
The above code prints:
construct before exception
destruct
This can't be right, or am I missing something? If I'm doing the same thing using NEW, everything works like expected, no Destructor is called. To me, this looks like a bug - any opinions? Is this known (haven't found anything on it)?
PS: As this is my very first question here, but I'm reading for a long time - thank you for this great site! It's almost always like: Google > Stackoverflow > Solution wit great Explanation :-)