From: adam at trachtenberg dot com
Operating system: *
PHP version: 5CVS-2003-11-15 (dev)
PHP Bug Type: Zend Engine 2 problem
Bug description: zend_parse_parameters() doesn't coerce overloaded objects into strings

Description:
------------
When passing an object with a __toString() method to a
function that uses zend_parse_parameters() with an "s"
value, PHP does not correctly coerce the object into a
string.

This occurs for both extensions (like SimpleXML) and
user-defined PHP classes.

Reproduce code:
---------------
class foo {
function __toString() {
return "foo";
}
}

$foo = new foo;
print strrev($foo) ."\n";
print htmlspecialchars($foo) ."\n";

Alternatively:

$xml = '<?xml version="1.0" ?><root><element>text</element></root>';
$s = simplexml_load_string($xml);
print strrev($s->element) ."\n";
print htmlspecialchars($s->element) ."\n";

Expected result:
----------------
oof
foo

Actual result:
--------------
PHP Warning: htmlspecialchars() expects parameter 1 to
be string, object given in foo.php on line 10
oof

strrev() uses convert_to_string_ex(), so it works fine.
htmlspecialchars() uses zend_parse_parms(), so there's a
warning.

--
Edit bug report at [url]http://bugs.php.net/?id=26265&edit=1[/url]
--
Try a CVS snapshot (php4): [url]http://bugs.php.net/fix.php?id=26265&r=trysnapshot4[/url]
Try a CVS snapshot (php5): [url]http://bugs.php.net/fix.php?id=26265&r=trysnapshot5[/url]
Fixed in CVS: [url]http://bugs.php.net/fix.php?id=26265&r=fixedcvs[/url]
Fixed in release: [url]http://bugs.php.net/fix.php?id=26265&r=alreadyfixed[/url]
Need backtrace: [url]http://bugs.php.net/fix.php?id=26265&r=needtrace[/url]
Try newer version: [url]http://bugs.php.net/fix.php?id=26265&r=oldversion[/url]
Not developer issue: [url]http://bugs.php.net/fix.php?id=26265&r=support[/url]
Expected behavior: [url]http://bugs.php.net/fix.php?id=26265&r=notwrong[/url]
Not enough info: [url]http://bugs.php.net/fix.php?id=26265&r=notenoughinfo[/url]
Submitted twice: [url]http://bugs.php.net/fix.php?id=26265&r=submittedtwice[/url]
register_globals: [url]http://bugs.php.net/fix.php?id=26265&r=globals[/url]
PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=26265&r=php3[/url]
Daylight Savings: [url]http://bugs.php.net/fix.php?id=26265&r=dst[/url]
IIS Stability: [url]http://bugs.php.net/fix.php?id=26265&r=isapi[/url]
Install GNU Sed: [url]http://bugs.php.net/fix.php?id=26265&r=gnused[/url]
Floating point limitations: [url]http://bugs.php.net/fix.php?id=26265&r=float[/url]