Bug #51524 [Com]: Class static method confusion
| From: | david71rj at gmail dot com | Date: | Mon, 12 Apr 2010 17:04:34 +0000 |
| Subject: | Bug #51524 [Com]: Class static method confusion | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-149518@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=51524&edit=1
ID: 51524
Comment by: david71rj at gmail dot com
Reported by: david71rj at gmail dot com
Summary: Class static method confusion
Status: Bogus
Type: Bug
Package: Scripting Engine problem
Operating System: Windows 7/64
PHP Version: 5.3.2
New Comment:
But how this not is a bug?
What I don't understand is: if I call a method as static, $this cannot
exists, one
time that $this, for me is 'object of same class' and not 'object of any
class'.
As example, how useful it (use $this as secondary object) can be?
Bye.
Previous Comments:
------------------------------------------------------------------------
[2010-04-12 11:48:46] pajoye@php.net
My comment was supposed to land in #51527, this one is obviously not a
bug (bogus).
------------------------------------------------------------------------
[2010-04-10 19:27:14] david71rj at gmail dot com
Not make sense, a call static is call static, don't can exist $this. In
counterpart, if the user need pass a object reference, he must be to
specific
how a parameter.
public function x($object = null){
if($object
&& get_class($object) == 'B') {
// Now make sense, but not is $this
}
}
Bye.
------------------------------------------------------------------------
[2010-04-10 18:06:02] pajoye@php.net
Not sure you can simply bogus it "because that's the way php4 works" :)
Should we not fix it in trunk instead? Or at least leave that request
open until we have a decision.
------------------------------------------------------------------------
[2010-04-10 17:49:31] johannes@php.net
If a static method is called from an object context the callers $this is
sent. This i due to compatibility with the way PHP 4 worked.
------------------------------------------------------------------------
[2010-04-10 03:37:23] david71rj at gmail dot com
Description:
------------
If I use public method as static in a method of a second function, this
send $this
from second class, don't of the first.
Test script:
---------------
http://codepad.org/8hW4Qtbo
Expected result:
----------------
array
0 => string 'static' (length=6)
1 => int 1
array
0 => string 'object' (length=6)
1 =>
object(test)[2]
2 => int 1
array
0 => string 'static' (length=6)
1 => int 1
array
0 => string 'object' (length=6)
1 =>
object(test)[3] <<<<<<<<<<<<<<< OKAY
2 => int 1
Actual result:
--------------
array
0 => string 'static' (length=6)
1 => int 1
array
0 => string 'object' (length=6)
1 =>
object(test)[2]
2 => int 1
array
0 => string 'static' (length=6)
1 => int 1
array
0 => string 'object' (length=6)
1 =>
object(test2)[3] <<<<<<<<< WHY "test2" IF DON'T?
2 => int 1
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51524&edit=1