Hi Nikita, hi all,
https://wiki.php.net/rfc/deprecations_php_7_2
I just realized that in Symfony, we use the $errcontext argument of error
handlers to work around the limitation of __toString not being able to
throw.
Excerpt from
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Debug/ErrorHandler.php#L439
:
// Here, we know trigger_error() has been called
from __toString().
// HHVM is fine with throwing from __toString() but
PHP triggers a fatal error instead.
// A small convention allows working around the
limitation:
// given a caught $e exception in __toString(),
quitting the method with
// `return trigger_error($e, E_USER_ERROR);` allows
this error handler
// to make $e get through the __toString() barrier.
This is a hack, but that's what the Debug component is about: leverage
several hacks and ship them as a set of useful experience-enhancers to devs.
In short, I'm all for deprecating $errcontext, and looking at the ongoing
vote it'll be accepted soon.
BUT, it would great to fix the inability of __toString to throw in 7.2 also.
Regards,
Nicolas