php.net |  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
Votes:1
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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pterjan at linuxfr dot org
New email:
PHP Version: OS:

 

 [2004-07-21 12:30 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-21 22:52 UTC] 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-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-2020 The PHP Group
All rights reserved.
Last updated: Thu Oct 01 05:01:24 2020 UTC