|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29294 $this is caller inside class methods
Submitted: 2004-07-21 12:30 UTC Modified: 2004-07-21 22:52 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: pterjan at linuxfr dot org Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.3.8 OS: GNU/Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
26 - 15 = ?
Subscribe to this entry?

 [2004-07-21 12:30 UTC] pterjan at linuxfr dot org
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:
        class Plop {
                function coin(){
                        echo get_class($this);
        class Foo {
                function plop(){
        $foo =& new Foo();

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-21 22:52 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Has been like this in PHP 4 too and we didn\'t want to break it in PHP 5.
 [2004-07-22 00:08 UTC] schlueter at phpbar dot de
An addition to Dericks comment: Defining plop::coin() as  
static prevents this with PHP5.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 22 12:01:29 2024 UTC