#29787 [Opn->Bgs]: Object instance variables not visible from within __toString()
| From: | helly@php.net | Date: | Sun, 22 Aug 2004 15:52:22 +0000 |
| Subject: | #29787 [Opn->Bgs]: Object instance variables not visible from within __toString() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-65055@lists.php.net to get a copy of this message | ||
ID: 29787
Updated by: helly@php.net
Reported By: adamgoossens at users dot sourceforge dot net
-Status: Open
+Status: Bogus
Bug Type: Zend Engine 2 problem
Operating System: Windows XP Professional, SP2
PHP Version: 5.0.1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
You didn't set the public var so its value is NULL.
Previous Comments:
------------------------------------------------------------------------
[2004-08-22 14:56:42] adamgoossens at users dot sourceforge dot net
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 this bug report at http://bugs.php.net/?id=29787&edit=1