|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52427 $this is used from the caller scope if the called method is static
Submitted: 2010-07-24 10:34 UTC Modified: 2013-02-18 00:34 UTC
From: tyra3l at gmail dot com Assigned:
Status: No Feedback Package: Class/Object related
PHP Version: 5.3.3 OS: all
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-07-24 10:34 UTC] tyra3l at gmail dot com
Samuel pointed out this "feature" on the php-windows mailing list:
this "feature" bit many people (see the bug reports, the comments on 
language.oop5.static.php), so I think we should add this behaviour to the 
"Because static methods are callable without an instance of the object
created, the pseudo-variable $this is not available inside the method
declared as static."

"Calling non-static methods statically generates an E_STRICT level warning."

We should add that the non-static methods can be called via the scope resolution 
operator (aka the static way) but in this case the method will have access to 
the caller method's scope and an E_STRICT warning will be raised.

Test script:
class A{

 public $foo = 'bar';

 public function write(){




class B{

 public $foo = 'gnagnagna';

 public function write(){




$var = new B;


Expected result:
PHP Fatal error:  Using $this when not in object context in...
Change in the documentation to describe this kind of behaviour.

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-24 11:28 UTC] tyra3l at gmail dot com
"The pseudo-variable $this is available when a method is called from within an 
object context. $this is a reference to the calling object (usually the object to 
which the method belongs, but possibly another object, if the method is called 
statically from the context of a secondary object)."

So it is indeed documented, maybe not on the best place of all...
 [2010-08-15 09:43 UTC]
-Status: Open +Status: Feedback
 [2010-08-15 09:43 UTC]
Where do you propose it should be documented instead?
 [2010-08-15 10:18 UTC] tyra3l at gmail dot com

this was the first two place where I tried to find documentation about this 

 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 12 16:01:35 2024 UTC