From: fm dot lheureux at gmail dot com
Operating system: Ubuntu 13.04x64
PHP version: Irrelevant
Package: Unknown/Other Function
Bug Type: Bug
Bug description:Different return value between within or without an object
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 bug report at https://bugs.php.net/bug.php?id=64886&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=64886&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=64886&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=64886&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=64886&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=64886&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=64886&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=64886&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=64886&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=64886&r=support
Expected behavior: https://bugs.php.net/fix.php?id=64886&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=64886&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=64886&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=64886&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64886&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=64886&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=64886&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=64886&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64886&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=64886&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=64886&r=mysqlcfg