Return value of convert_to_*()
| From: | Andrei Zmievski | Date: | Wed, 27 Dec 2006 20:02:29 +0000 |
| Subject: | Return value of convert_to_*() | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-27204@lists.php.net to get a copy of this message | ||
Antony and I just had a spirited discussion on IRC about his latest patches to convert_to_unicode() and convert_to_string(). The specific troublesome point was conversion of IS_OBJECT type. His point was that since all we care about is the end result, then the function should return SUCCESS regardless of whether the object could convert itself to a string or whether we forced the conversion and got a simple "Object" string. I do not subscribe to this point of view. I added return values to conversion functions precisely because I wanted to distinguish between "good" and "forced" conversions. We can convert anything to anything, that's not a problem, but in certain cases I do care that we tried to convert IS_OBJECT to IS_STRING and couldn't do it without falling back onto the "Object" crutch. One such place is zend_parse_parameters(). If you say zpp(..., "s", &str, &str_len) and the user passes an object without __toString() method, zpp() should issue an error saying that it expected a string and got an object instead, even if we "forced" the conversion result to be a string in convert_to_string().
My problem with considering "Object" a "successful" conversion is this: why do we issue E_RECOVERABLE error if the object couldn't convert itself to a string? Why should the user be able to catch that and not my code?
Please tell me that this is a valid point of view.
-Andrei