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

Reply via email to