#29787 [Bgs]: Object instance variables not visible from within __toString()
| From: | adamgoossens at users dot sourceforge dot net | Date: | Mon, 23 Aug 2004 08:25:06 +0000 |
| Subject: | #29787 [Bgs]: Object instance variables not visible from within __toString() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-65080@lists.php.net to get a copy of this message | ||
ID: 29787
User updated by: adamgoossens at users dot sourceforge dot net
Reported By: adamgoossens at users dot sourceforge dot net
Status: Bogus
Bug Type: Zend Engine 2 problem
Operating System: Windows XP Professional, SP2
PHP Version: 5.0.1
New Comment:
Oops. And I thought I had been so careful and checked everything. :)
Apologies for wasting your time.
Previous Comments:
------------------------------------------------------------------------
[2004-08-22 17:52:20] helly@php.net
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.
------------------------------------------------------------------------
[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