php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62333 Cannot statically call method to parent class
Submitted: 2012-06-15 11:11 UTC Modified: 2012-06-21 08:15 UTC
From: Sjon at hortensius dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: Irrelevant OS:
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: Sjon at hortensius dot net
New email:
PHP Version: OS:

 

 [2012-06-15 11:11 UTC] Sjon at hortensius dot net
Description:
------------
All static calls to a class-parent end up being non-static

Inconsistency clearly proven:

http://3v4l.org/Mkn0L
http://3v4l.org/1L3Wk (same, but without __call)

Test script:
---------------
See http://3v4l.org/Mkn0L

<?php

class A
{
	public function __call($name, $args)
	{
		echo "Not static\n";
	}

    public static function __callStatic($name, $args)
	{
		echo "Static\n";
	}
}

class B extends A
{
    public function test()
	{
		forward_static_call(array('A', 'stuff'));
		call_user_func(array('A', 'stuff'));
		A::stuff();
	}
}

class C
{
	public function test()
	{
		forward_static_call(array('A', 'stuff'));
		call_user_func(array('A', 'stuff'));
		A::stuff();
	}
}

A::test();

echo " = B =\n";
$b = new B();
$b->test();

echo " = C =\n";
$c = new C();
$c->test();

Expected result:
----------------
Static
 = B =
Not static
Not static
Not static
 = C =
Static
Static
Static

Actual result:
--------------
Static
 = B =
Not static
Not static
Not static
 = C =
Static
Static
Static

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-19 08:32 UTC] cataphract@php.net
Not a bug. A::foo() is not necessarily a static call. Namely, if foo() is not static and there is a compatible context ($this exists and its class is either the class of the target method or a subclass of it), an instance call will be made. In your case, because you sort of have a static and non-static foo() via magic, the non-static is preferred. You'll have to be creative, like maybe calling __callstatic directly or using a closure.
 [2012-06-19 08:32 UTC] cataphract@php.net
-Status: Open +Status: Not a bug
 [2012-06-21 08:15 UTC] Sjon at hortensius dot net
You describe my exact problem, but why deny this is a bug? I understand this 
would be unfixable without breaking implementations that depend on this 
behaviour, but I do not understand that you deny the huge inconsistency, thus 
preferably fixable behaviour that PHP has here?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 09:01:27 2024 UTC