Stanislav Malyshev wrote:
So the problem basically is that in PHP 7.0 both print_r and var_dump directly
print to output. This means that by the time the exception is thrown, we've
already written output. This makes it unclear how exactly the exception should
be handled. Is it okay to just print everything and handle the exception
afterward? This seems odd to me -- if an operation fails it shouldn't do
This sounds nice in theory, in practice often impossible. I.e. if you
already started printing and then some dependency fails, then you get
half-printed output. That's fine IMHO. Exception is not a normal
condition, so you get result which is not normal.
In PHP 7.1 I've rewritten print_r() to use an internal buffer, so we could
this case completely gracefully. The same change could be implemented for
var_dump(). With this approach we'd only print anything if no exception
This is ok, but I don't think it's required. If you've got in exception
in conversion, all bets are off, any result that passes a low sanity
margin IMHO is ok - including both printing whatever happened before the
exception and not printing anything.
I also think that the exception firing mid-output isn't all that
unreasonable. If you were to implement var_dump() or print_r() yourself
in userland, and didn't explicitly handle this case, you'd get the same
result, I imagine.
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php