php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48714 When calling parent class method, self is responding
Submitted: 2009-06-29 09:17 UTC Modified: 2009-08-02 12:31 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (33.3%)
From: sebcorne at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.0RC4 OS: Windows
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: sebcorne at gmail dot com
New email:
PHP Version: OS:

 

 [2009-06-29 09:17 UTC] sebcorne at gmail dot com
Description:
------------
Tested on php5.3.0-alpha3 (must be tested on last snap)

When calling parent class method, self is responding

(sorry for my bad english)

Reproduce code:
---------------
class base
{
	public function __call($name, $arguments)
	{
		echo get_called_class() . "->$name() is called \n\n";
	}
}


class A extends base
{
	public function parent_automatic()
	{
		$parentclass = get_parent_class($this);
		echo get_class($this) . '->'. __FUNCTION__ ."() call $parentclass::test() \n";
		$parentclass::test();
	}
	
	public function parent_manual()
	{
		echo get_class($this) . '->'. __FUNCTION__ ."() call A::test() \n";
		A::test();
	}
}


class B extends A {}



$b = new B;
$b->parent_automatic();
$b->parent_manual();


Expected result:
----------------
B->parent_automatic() call A::test() 
A->test() is called 

B->parent_manual() call A::test() 
A->test() is called 


Actual result:
--------------
B->parent_automatic() call A::test() 
B->test() is called 

B->parent_manual() call A::test() 
B->test() is called 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-30 05:45 UTC] sebcorne at gmail dot com
class base
{
	static public function __callstatic($name, $arguments)
	{
		echo get_called_class() . "::$name() is called \n\n";
	}
	public function __call($name, $arguments)
	{
		echo get_called_class() . "->$name() is called \n\n";
	}
}



give the same result.
but without "__call()", it's ok.

if "$this" exists in inheritance, "__call()" (of $this) is called instead of "__callstatic()"
 [2009-06-30 14:05 UTC] sjoerd-php at linuxonly dot nl
Thank you for your bug report.

Are you sure the behavior you describes is not documented? Please take a look at:
http://nl.php.net/manual/en/language.oop5.late-static-bindings.php#language.oop5.late-static-bindings.edge-cases
 [2009-06-30 17:12 UTC] sebcorne at gmail dot com
Yes, it's documented :
"it might give unexpected results in so-called edge cases"

I see two problems :
- self class respond
- "__call()" is called instead of "__callstatic()"

There is not means to solve that ?
 [2009-07-24 09:44 UTC] colder@php.net
> I see two problems :
> - self class respond
> - "__call()" is called instead of "__callstatic()"

That is because the call is not static. $name::method() is not sufficient to garantee a static call:
- the target method has to be static or 
- the current scope has to be void

In your case, the definition of the target method is not explicit, as test() is not defined and you have both __call and __callStatic. Since the current scope exists, it will use __call by default.

 [2009-08-02 12:31 UTC] sebcorne at gmail dot com
Thanks for the explications.
You can close this report
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 21 08:00:02 2025 UTC