#29294 [Com]: $this is caller inside class methods
| From: | schlueter at phpbar dot de | Date: | Wed, 21 Jul 2004 22:09:01 +0000 |
| Subject: | #29294 [Com]: $this is caller inside class methods | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-63295@lists.php.net to get a copy of this message | ||
ID: 29294
Comment by: schlueter at phpbar dot de
Reported By: pterjan at linuxfr dot org
Status: Bogus
Bug Type: Class/Object related
Operating System: GNU/Linux
PHP Version: 4.3.8
New Comment:
An addition to Dericks comment: Defining plop::coin() as
static prevents this with PHP5.
Previous Comments:
------------------------------------------------------------------------
[2004-07-21 22:52:12] derick@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
Has been like this in PHP 4 too and we didn\'t want to break it in PHP
5.
------------------------------------------------------------------------
[2004-07-21 12:30:58] pterjan at linuxfr dot org
Description:
------------
When a method is called outside any instance, I would expect $this not
being defined, however, if the method is called from another object, it
will point to the caller.
Is it intended ?
Reproduce code:
---------------
<?php
class Plop {
function coin(){
echo get_class($this);
}
}
class Foo {
function plop(){
Plop::coin();
}
}
$foo =& new Foo();
$foo->plop();
?>
Expected result:
----------------
Nothing
Actual result:
--------------
foo
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29294&edit=1