|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-05-21 02:53 UTC] fm dot lheureux at gmail dot com
[2013-05-21 06:58 UTC] nikic@php.net
[2013-05-21 06:58 UTC] nikic@php.net
-Status: Open
+Status: Not a bug
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 20:00:01 2025 UTC |
Description: ------------ I would expect a getter to return the same value whether it's being called within or without an object. In my example, my __get function always returns null. If it's being called from outside the object, it behaves properly and returns null. If it's being called from inside, it returns the object itself. Here I used the __get function to make it even clearer, but it does the same regardless of the presence of that function. Test script: --------------- <?php class Toto{ function __get($p){ return null; } function doit(){ echo get_class($this->wololo); //this will print "TOTO", but why? } } $t = new Toto(); $t->doit(); echo "\n"; echo get_class($t->wololo); //this will not work, which is what I expect echo "\n"; Expected result: ---------------- PHP Warning: get_class() called without object from outside a class in /home/fmlheureux/test.php on line 9 PHP Warning: get_class() called without object from outside a class in /home/fmlheureux/test.php on line 16 Actual result: -------------- Toto PHP Warning: get_class() called without object from outside a class in /home/fmlheureux/test.php on line 16