php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47891 static method bound to calling object
Submitted: 2009-04-03 16:36 UTC Modified: 2009-04-03 16:52 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: slava at forma dot kharkov dot ua Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: 5.2.9 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: slava at forma dot kharkov dot ua
New email:
PHP Version: OS:

 

 [2009-04-03 16:36 UTC] slava at forma dot kharkov dot ua
Description:
------------
this code prints instance of object "b" and doesn't throw any errors or exceptions. If a::stat has modificator "static" it says "Notice: Undefined variable: this" and prints null.

Reproduce code:
---------------
class a
{
	public function stat()
	{
	    var_dump($this);
	}
}

class b
{
	public function test()
	{
		a::stat();
	}
}

$b= new b();
$b->test();


Expected result:
----------------
throws some errors or exceptions. 

Actual result:
--------------
prints instance of object "b"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-03 16:52 UTC] colder@php.net
This is expected, :: calls a method of a class using th current context as call context. Hence $this in a::stat is a b object. It will issue a Strict warning.

It's kept that way in PHP5 for PHP4 backward compatibility reasons but it may be cleaned up in PHP6.


 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Jan 21 22:01:23 2021 UTC