Re: Return value of convert_to_*()

From: Date: Wed, 27 Dec 2006 20:23:11 +0000
Subject: Re: Return value of convert_to_*()
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-27205@lists.php.net to get a copy of this message
On 12/27/2006 11:02 PM, Andrei Zmievski wrote:
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.
Why do you want that? "Bad" conversion is failed conversion, that's the case when you get E_RECOVERABLE_ERROR and it bails out. I consider all the other cases are "good" conversions, since we've got the result we requested and have SUCCESSfully converted the object into string.
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().
An error? You mean this one: zend_error(E_NOTICE, "Object of class %v to string conversion", Z_OBJCE_P(op)->name); ? We already have it, no need for a new error. It's perfectly legal to do it in 5.2 and I don't see why PHP6 is different. IMO it's same as changing the E_RECOVERABLE to E_ERROR - users won't have any way to "workaround" it, even though this was the original intention of E_RECOVERABLE. -- Wbr, Antony Dovgal

« previous php.internals (#27205) next »