|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9005 Static classes sometimes have a $this pointer
Submitted: 2001-01-30 13:39 UTC Modified: 2001-03-08 05:51 UTC
From: chuck at horde dot org Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.4pl1 OS: Linux 2.2
Private report: No CVE-ID: None
 [2001-01-30 13:39 UTC] chuck at horde dot org
If you call a static method from within an object, the static method will inherit the $this pointer of the calling object. This script demonstrates the problem:



class StaticClass {
    function doSomething() {
        echo $this->data;

class Instantiated {
    var $data;

    function Instantiated($data) {
        $this->data = $data;

$ob = new Instantiated('foo');


This is rather confusing behavior - $this should be out of scope inside static methods no matter what.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-08 05:51 UTC]
class::method() isn't a static call in PHP (it isn't always a static call in C++ either).
The primary use for class::method() is actually calling methods from your parent class, not calling 'static methods' (the ability to create static classes and call their methods is pretty much a positive 'side effect').

So, this is the intended behavior.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Sep 30 17:01:24 2023 UTC