#33856 [Opn->Bgs]: $this shining through
| From: | helly@php.net | Date: | Mon, 25 Jul 2005 21:50:52 +0000 |
| Subject: | #33856 [Opn->Bgs]: $this shining through | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-82428@lists.php.net to get a copy of this message | ||
ID: 33856
Updated by: helly@php.net
Reported By: sr at brightlight dot ch
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
-Operating System: Mac OS X 10.4.1
+Operating System: *
-PHP Version: 5.0.4
+PHP Version: 5.*
New Comment:
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
Mark the function as static. It is only possible to call non static
methods as static methods for BC reasons.
Previous Comments:
------------------------------------------------------------------------
[2005-07-25 23:46:58] sr at brightlight dot ch
Description:
------------
If a method is called via object::method(); from within a
class method, then inside of the object::method(); the $this
from the calling class method is visible.
This makes it almost impossible to tell if a method was
invoked via -> or ::
Reproduce code:
---------------
<?php
$test = new testclass();
$test->test();
class testclass {
function test() {
otherclass::staticFunction();
normalFunction();
}
}
class otherclass {
function staticFunction() {
echo "staticFunction: ".(isset($this) ? "set and of class:
".get_class($this)."\n" : "not set\n");
}
}
function normalFunction() {
echo "normalFunction: ".(isset($this) ? "set and of class:
".get_class($this)."\n" : "not set\n");
}
?>
Expected result:
----------------
staticFunction: not set
normalFunction: not set
Actual result:
--------------
staticFunction: set and of class: testclass
normalFunction: not set
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=33856&edit=1