#33361 [Opn->WFx]: $this in static context
| From: | tony2001@php.net | Date: | Thu, 16 Jun 2005 11:57:06 +0000 |
| Subject: | #33361 [Opn->WFx]: $this in static context | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-80430@lists.php.net to get a copy of this message | ||
ID: 33361
Updated by: tony2001@php.net
Reported By: halmai at nexum dot hu
-Status: Open
+Status: Wont fix
Bug Type: Feature/Change Request
Operating System: Linux
PHP Version: 4.3.10
New Comment:
As this is not a bug, it won't be changed in 4.3/4.4, because this is a
bugfix-only branch.
Previous Comments:
------------------------------------------------------------------------
[2005-06-16 13:52:03] halmai at nexum dot hu
Sorry, I forgot to reopen the state of this report.
------------------------------------------------------------------------
[2005-06-16 13:39:24] halmai at nexum dot hu
I know that this is not a bug. This is a feature, but a really silly
and useless feature.
That's why I reported it as a "feature/change request".
------------------------------------------------------------------------
[2005-06-16 13:28:24] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
.
------------------------------------------------------------------------
[2005-06-16 13:14:55] halmai at nexum dot hu
Description:
------------
I have two classes with one function respectively.
In any function the variable $this should mean
- the instance of the class if this function was called as a function
of an instance of _that_ class, and
- it should be undefined (null) if called as a static function.
My problem is that if I call a static function of a class A from a
non-static function of class B then in the member function of class A
the variable $this denotes the instance of the class B instead of being
null.
The fact that in a function of class A the variable $this denotes an
instance of class B is really confusing. If it was called statically
then $this should be null.
I know that this is described as normal behaviour but I think this is a
useless and senseless feature. In case of accepting my suggestion it
would be easy to decide whether a function was called in a static or
non-static context.
Reproduce code:
---------------
class A {
function what_am_i() {
if ( $this === null ) {
print "i am not an instance<br>";
} else {
print "i am an instance from the class '".get_class( $this
)."'.<br>";
}
}
}
class B {
function wrapper() {
A::what_am_i();
}
}
A::what_am_i(); // i am not an instance (this is OK)
$a = new A();
$a -> what_am_i(); // i am an instance from the class 'a'. (this is
OK)
$b = new B();
$b -> wrapper(); // i am an instance from the class 'b'. (this should
output not an instance)
Expected result:
----------------
i am not an instance
i am an instance from the class 'a'.
i am not an instance
Actual result:
--------------
i am not an instance
i am an instance from the class 'a'.
i am an instance from the class 'b'.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=33361&edit=1