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
 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 21:01:28 2024 UTC