Edit report at https://bugs.php.net/bug.php?id=64886&edit=1

 ID:                 64886
 User updated by:    fm dot lheureux at gmail dot com
 Reported by:        fm dot lheureux at gmail dot com
 Summary:            Different return value between within or without an
                     object
 Status:             Open
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   Ubuntu 13.04x64
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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!


Previous Comments:
------------------------------------------------------------------------
[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

Reply via email to