php.net |  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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chuck at horde dot org
New email:
PHP Version: OS:

 

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

<?php

error_reporting(E_ALL);

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

class Instantiated {
    var $data;

    function Instantiated($data) {
        $this->data = $data;
        StaticClass::doSomething();
    }
}

$ob = new Instantiated('foo');

?>


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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-08 05:51 UTC] zeev@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 01:01:29 2024 UTC