From: tudor at tudorholton dot com Operating system: Ubuntu PHP version: 5.2SVN-2009-09-05 (snap) PHP Bug Type: Scripting Engine problem Bug description: Multiple object selection operators in quoted strings
Description: ------------ This is actually on Ubuntu Jaunty which is PHP version 5.2.6-3ubuntu4.2 Using multiple object access operators in a row inside a double-quoted string causes the error: Catchable fatal error: Object of class ... could not be converted to string The problem is that the operators are interpreted from left to right and then converted to string. The last operation should be that the object is converted to a string. This is particularly important when using OO code because frequently the current object ($this) references another object and then gets an attribute from that. e.g. $this->that->attribute Reproduce code: --------------- <?php class A { var $attr = 'Hello A!'; } class B { var $a; var $attr = "Hello B!"; function __construct() { $this->a = new A(); } function output() { echo "$this->attr"; } } $b = new B(); $b->output(); echo "$b->attr"; echo "$b->a->attr"; ?> Expected result: ---------------- Hello B!Hello B!Hello A! Actual result: -------------- Hello B!Hello B! Catchable fatal error: Object of class A could not be converted to string in test.php on line 19 -- Edit bug report at http://bugs.php.net/?id=49471&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49471&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49471&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49471&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49471&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49471&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49471&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49471&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49471&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49471&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49471&r=support Expected behavior: http://bugs.php.net/fix.php?id=49471&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49471&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49471&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49471&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49471&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=49471&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49471&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49471&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49471&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49471&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49471&r=mysqlcfg