You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe the assertion is just too presumptious, given that an error handler may throw. Removing it, makes the given script pass. But that requires more thorough investigation, and I'm somewhat concerned that existing observers might make the same assumption.
I mean, this is a common programming idiom, so this is definitely a bug. Technically it doesn't seem strictly necessary to bail here, since inheritance wasn't aborted. However, note that inheritance may still accidentally abort due to EG(exception) being set.
After removing the ZEND_ASSERT():
set_error_handler(function($_, $msg) {
thrownewException($msg);
});
spl_autoload_register(function() {});
class P {
publicfunctiontest(): X {}
}
class UnSerializable extends P implements Serializable {
publicfunctionserialize() {}
publicfunctionunserialize($serialized) {}
publicfunctiontest(): Y {}
}
Fatal error: During inheritance of UnSerializable, while autoloading Y: Uncaught Exception: UnSerializable implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary)
If there were no error handlers, this ticket would be invalid, and more generally section 3.5 of https://biagiocosenza.com/papers/PopovCC17.pdf would no longer apply (and yes, I'm aware that $errcontext is gone as of PHP 8.0.0, but still error handlers allow for spooky action at a distance).
Ah ^^ I agree that error handlers were a bad idea. I spent quite a bit of time last year trying to solve related issues. I also looked into alternatives with the possibility of deprecating them, but Nicolas Grekas didn't consider the alternative to be feature-complete.
zend_error(E_DEPRECATED, "%s implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary)", ZSTR_VAL(class_type->name));
Analogous to the code in c8fa477. Given the example from this comment, it isn't currently possible to handle this gracefully, as other code paths can still trigger a fatal error when promoting these warnings to exceptions.
Activity
cmb69 commentedon Sep 16, 2024
Relevant commit: c8fa477
Maybe the assertion is just too presumptious, given that an error handler may throw. Removing it, makes the given script pass. But that requires more thorough investigation, and I'm somewhat concerned that existing observers might make the same assumption.
Tentatively qualifying this as bug.
[-]Core dumped in Zend/zend_compile.c[/-][+]Assertion failure in Zend/zend_compile.c[/+]iluuu1994 commentedon Sep 17, 2024
I mean, this is a common programming idiom, so this is definitely a bug. Technically it doesn't seem strictly necessary to bail here, since inheritance wasn't aborted. However, note that inheritance may still accidentally abort due to
EG(exception)being set.After removing the
ZEND_ASSERT():Not sure what the best resolution is.
cmb69 commentedon Sep 17, 2024
You are referring to throwing from an error handler? Yeah, that would be common.
But imagine there were no error handlers …
iluuu1994 commentedon Sep 17, 2024
I don't follow. 🙂
cmb69 commentedon Sep 17, 2024
If there were no error handlers, this ticket would be invalid, and more generally section 3.5 of https://biagiocosenza.com/papers/PopovCC17.pdf would no longer apply (and yes, I'm aware that
$errcontextis gone as of PHP 8.0.0, but still error handlers allow for spooky action at a distance).iluuu1994 commentedon Sep 17, 2024
Ah ^^ I agree that error handlers were a bad idea. I spent quite a bit of time last year trying to solve related issues. I also looked into alternatives with the possibility of deprecating them, but Nicolas Grekas didn't consider the alternative to be feature-complete.
iluuu1994 commentedon Sep 17, 2024
I would suggest adding a
if (EG(exception)) zend_exception_uncaught_error();here:php-src/Zend/zend_interfaces.c
Line 480 in 43dc2eb
Analogous to the code in c8fa477. Given the example from this comment, it isn't currently possible to handle this gracefully, as other code paths can still trigger a fatal error when promoting these warnings to exceptions.
WDYT?
cmb69 commentedon Sep 18, 2024
That could be
I think this makes perfect sense.
Fix failed assertion when promoting Serialize deprecation to exception