|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-08-22 17:52 UTC] helly@php.net
[2004-08-23 10:25 UTC] adamgoossens at users dot sourceforge dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 13:00:01 2025 UTC |
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.