php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52713 Can't call undefined methods (using __call) on parent
Submitted: 2010-08-27 06:06 UTC Modified: 2011-01-28 21:52 UTC
Votes:5
Avg. Score:4.8 ± 0.4
Reproduced:5 of 5 (100.0%)
Same Version:4 (80.0%)
Same OS:3 (60.0%)
From: michael at wakeless dot net Assigned: felipe (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.3 OS: All
Private report: No CVE-ID: None
 [2010-08-27 06:06 UTC] michael at wakeless dot net
Description:
------------
When using the __call and __callStatic functionality on a parent class calls to parent::method() will always use __callStatic rather than the __call. 

This breaks backwards compatibility in a number of cases.

Test script:
---------------
class A {
  function __call($method, $args) {
    if($method == "Test") {
      echo "Success.";
    }
  }
  
  function __callStatic($method, $args) {
    echo "Failure.";
  }
}

class B extends A {
  function Test() {
    echo "Test called.";
    parent::Test();
  }
}

$test = new B;
$test->Test();


Expected result:
----------------
//Expected output: Test called.Success.

Actual result:
--------------
//Actual output: Test called.Failure

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-28 22:38 UTC] giovanni at giacobbi dot net
I ran into the same problem.

It's a serious breakage! I just tested on php 5.3.2 and it works as expected!
 [2010-08-31 01:05 UTC] felipe@php.net
The difference introduced was that the __call() just will be called when __callStatic() is not implemented, on such static method calls.
 [2010-08-31 01:06 UTC] felipe@php.net
The change was introduced as a fix for the bug #51176.
 [2010-08-31 06:06 UTC] michael at wakeless dot net
I'm pretty sure everyone should be aware of this but I'll say it nonetheless.

parent:: isn't necessarily a static call. When it's used within an object context it should remain within an object context, but the subsequent call to __callStatic seems to lose it.

I tried a workaround of testing for $this in __callStatic but it seems to have gone missing.

Is there anything I can do to help this out? Write a more comprehensive test case that can be checked into the suite?
 [2010-08-31 14:48 UTC] giovanni at giacobbi dot net
@michael: I think the situation is perfectly clear. I think they screwed up on this one.

@felipe: this change is absolutely not reasonable and breaks backward compatibility. I understand that the behaviour for #51176 is inconvenient, but that's the way it is, you cannot change this in a minor release.

My suggestion (and wish) is that you revert this change to the previous behaviour. Shall we discuss this in the internals mailing list? Sounds like an interesting issue without a straightforward solution.giov
 [2011-01-11 17:52 UTC] ghosh at q-one dot com
Is this still problem with PHP 5.3.4?
Following the discussion here:

http://www.serverphorums.com/read.php?7,220473,220473#msg-220473

it seems this should already been fixed. This bug, however, is still marked as open.
 [2011-01-28 21:52 UTC] felipe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: felipe
 [2011-01-28 21:52 UTC] felipe@php.net
Yes, it has been already fixed in 5.3.4.

Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC