Re: Allow exceptions in __toString()
| From: | Johannes Schlüter | Date: | Thu, 25 Jun 2015 13:55:16 +0000 |
| Subject: | Re: Allow exceptions in __toString() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-86863@lists.php.net to get a copy of this message | ||
On Thu, 2015-06-25 at 14:52 +0200, Nikita Popov wrote:
> However what it doesn't do, and what I wouldn't consider feasible to do, is
> ensure that every single string conversion in library functions is
> exception safe. Personally I don't think this is a blocking issue, as the
> worst that can happen is usually an additional superfluous warning to be
> thrown, or something similar. If cases like this turn up, we can
> specifically target them.
I don't agree to the assesment that this isn'T a problem. Consider this
extension pseudo-code:
zval *data = get_data();
convert_to_string(data);
store_into_database(Z_STRVAL_P(data));
return TRUE;
This will store wrong data in the database and report to the user that
there was an error before storing, so the user assumes nothing was
stored.
The only way we can do that imo is by bailing out if an exception is
thrown and introducing yet another set of string conversion functions
for marking exception safe uses. (i.e. convert_to_string_throwing())
johannes