php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34046 $this accessible in static mehods called by an object not instance of this clas
Submitted: 2005-08-09 08:47 UTC Modified: 2005-08-09 09:19 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: bugs dot php dot net at sebastianmendel dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4CVS-2005-08-09 (stable) OS: Irrelevant
Private report: No CVE-ID: None
 [2005-08-09 08:47 UTC] bugs dot php dot net at sebastianmendel dot de
Description:
------------
$this is available inside a statically called mehod when it is called from inside an object not an instance of this class

Reproduce code:
---------------
<?php
class Foo {
    function foo() {
        if ( isset( $this ) ) {
            return '$this available';
        } else {
            return '$this NOT available';
        }
    }
}
class Bar {
    function callFoo() {
        echo 'Foo::foo(): ' . Foo::foo() . "\n";
    }
}

$foo = new Bar();
$foo->callFoo();
?>

Expected result:
----------------
Foo::foo(): $this NOT available

Actual result:
--------------
Foo::foo(): $this available

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-09 08:49 UTC] bugs dot php dot net at sebastianmendel dot de
see also answer to bug #9005

http://bugs.php.net/bug.php?id=9005
 [2005-08-09 08:49 UTC] derick@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.

 [2005-08-09 08:56 UTC] bugs dot php dot net at sebastianmendel dot de
$this should not be available inside a method called with the scope-resolution-operator if the call comes from an object not beeing an instance of the same class as the called method
 [2005-08-09 09:06 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

.
 [2005-08-09 09:19 UTC] bugs dot php dot net at sebastianmendel dot de
i read both. and the doc more than once

the scope resolution operator is to call methods from a parent class, and there should $this available.

but why is $this available when the method is not of a parent class?

btw. doesnt it pollutes the lokal namespace?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Dec 01 23:00:02 2025 UTC