Edit report at https://bugs.php.net/bug.php?id=64886&edit=1
ID: 64886 Updated by: ni...@php.net Reported by: fm dot lheureux at gmail dot com Summary: Different return value between within or without an object -Status: Open +Status: Not a bug Type: Bug Package: Unknown/Other Function Operating System: Ubuntu 13.04x64 PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. Previous Comments: ------------------------------------------------------------------------ [2013-05-21 02:53:30] fm dot lheureux at gmail dot com This bug can be killed. When writing it I realized my mistake. When the get_class method is invoked with the null parameter, it returns the class of where it's being called, hence "Toto". Not a bug! ------------------------------------------------------------------------ [2013-05-21 02:38:07] fm dot lheureux at gmail dot com 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64886&edit=1