php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68055 Calls from incompatible contexts do weird things
Submitted: 2014-09-19 16:55 UTC Modified: 2014-09-19 17:28 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: m-a-x at kpitv dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.4.33 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: m-a-x at kpitv dot net
New email:
PHP Version: OS:

 

 [2014-09-19 16:55 UTC] m-a-x at kpitv dot net
Description:
------------
$C->someFunction();
must be same as 
C::someFunction();
but we have 
Fatal error: Access to undeclared static property: C::$test 


It is strange that it is still not fixed

Test script:
---------------
<?
phpinfo();
class A
{
	function test()
	{
		echo get_called_class(),"\n";
		echo static::$test,"\n\n";
	}	
}

class B extends A
{
	static $test = 'B';	
}

class C
{
	function someFunction()
	{
		B::test();		
	}
}

B::test();
C::someFunction();
$C = new C();
$C->someFunction();


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-09-19 17:28 UTC] aharvey@php.net
-Summary: 1 +Summary: Calls from incompatible contexts do weird things -Status: Open +Status: Not a bug -Package: *General Issues +Package: Scripting Engine problem
 [2014-09-19 17:28 UTC] aharvey@php.net
This is already being dealt with: in PHP 5.6, the following deprecation warning will be emitted:

Deprecated: Non-static method A::test() should not be called statically, assuming $this from incompatible context in /private/tmp/test.php on line 20

The deprecation is documented at http://php.net/manual/en/migration56.deprecated.php#migration56.deprecated.incompatible-context — in the longer term, I expect this will be removed, probably in PHP 7.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 11:00:02 2026 UTC