From: adamgoossens at users dot sourceforge dot net
Operating system: Windows XP Professional, SP2
PHP version: 5.0.1
PHP Bug Type: Zend Engine 2 problem
Bug description: Object instance variables not visible from within __toString()
Description:
------------
Hi folks,
When overriding __toString() to provide custom object to string conversion
it appears as though object level variables are not visible from within the
function.
This affects public, private and protected variables equally. Static
member variables and class constants are not affected.
Reproduce code:
---------------
class Foo
{
public $_myVar;
public static $_static = 'I am static.';
const MY_CONST = 'I am constant.';
function __construct()
{
$_myVar = 'A public variable.';
}
function __toString()
{
return
"Variables:\n".$this->_myVar."\n".Foo::$_static."\n".Foo::MY_CONST;
}
}
$foo = new Foo;
echo $foo;
Expected result:
----------------
Variables:
A public variable.
I am static.
I am constant.
Actual result:
--------------
Variables:
I am static.
I am constant.
--
Edit bug report at http://bugs.php.net/?id=29787&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29787&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=29787&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=29787&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=29787&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=29787&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=29787&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=29787&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=29787&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=29787&r=support
Expected behavior: http://bugs.php.net/fix.php?id=29787&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=29787&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=29787&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=29787&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29787&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=29787&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=29787&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=29787&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29787&r=float