php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42595 Static call of non static function inherets class
Submitted: 2007-09-08 02:02 UTC Modified: 2007-09-09 10:27 UTC
From: agideonse at planet dot nl Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.4 OS: Irrelevant
Private report: No CVE-ID: None
 [2007-09-08 02:02 UTC] agideonse at planet dot nl
Description:
------------
When a function in a class is not declared static it can still be called as a static method (no problem). When this is done from another class the function seems to know the values from the class that it was called from. It is not clarified in the manual why this should be the case ($this is bound to class A, not class B) if this isn't a bug.

Reproduce code:
---------------
class A
{
   function __construct()
   {
      $this->name = "Class A";
   }

   function doeIets()
   {
      B::doeIetsAnders();
   }
}

class B
{
   function doeIetsAnders()
   {
      print_r($this);
   }
} 

Expected result:
----------------
In strict mode, there should be a warning that $this does not have a value.

Actual result:
--------------
$this has te values of class A. 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-09 10:27 UTC] jani@php.net
See bug #42559
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Aug 16 01:00:02 2025 UTC