Bug #52969 [Opn->Bgs]: This defined in static call from within another class
| From: | cataphract@php.net | Date: | Sat, 02 Oct 2010 18:07:43 +0000 |
| Subject: | Bug #52969 [Opn->Bgs]: This defined in static call from within another class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-154834@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52969&edit=1
ID: 52969
Updated by: cataphract@php.net
Reported by: ircmaxell at yahoo dot com
Summary: This defined in static call from within another
class
-Status: Open
+Status: Bogus
Type: Bug
Package: Class/Object related
Operating System: linux
PHP Version: 5.3.3
Block user comment: N
New Comment:
Closing as bogus. As you have pointed out, this is documented.
Previous Comments:
------------------------------------------------------------------------
[2010-10-02 15:51:04] gnuffo1 at gmail dot com
It has been pointed out to me that this is actually documented:
http://us2.php.net/manual/en/language.oop5.basic.php
Under example 2 and specifically the lines:
$b = new B();
$b->bar();
------------------------------------------------------------------------
[2010-10-02 15:33:50] php at rwasmus dot nl
Can reproduce across architectures & versions from 5.2.9 onward, IMHO
opinion, just an E_STRICT error in between is understating the scripters
design flaw. Some existing code may rely on it, so a real fix may hurt
some packages, but at the very least I'd increase the errors severity.
------------------------------------------------------------------------
[2010-10-02 15:33:00] ircmaxell at yahoo dot com
Oh, and $this is an object of class Test2 within Test1::getName()...
------------------------------------------------------------------------
[2010-10-02 15:28:02] gnuffo1 at gmail dot com
This seems to have existed way back in PHP 4.1:
http://www.advogato.org/article/470.html
If this is a bug, then I think it should be turned into a feature and
documented. It is occasionally useful for trait-like functionality.
------------------------------------------------------------------------
[2010-10-02 15:24:18] ircmaxell at yahoo dot com
Description:
------------
When calling a non-static method statically from within another class
(non-
inherited), $this is populated with the other object's class.
Test script:
---------------
class test1 {
public function getName() {
return $this->name;
}
}
class test2 {
public $name = 'foo';
public function getName() {
return test1::getName();
}
}
$obj = new Test2;
echo $obj->getName();
Expected result:
----------------
Fatal Error: Using $this when not in object context
Actual result:
--------------
"foo" is outputted.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52969&edit=1