php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #41866 method overloading works "correctly" but not "as described"
Submitted: 2007-07-01 21:26 UTC Modified: 2007-08-16 23:51 UTC
From: ozone at cname dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: netbsd
Private report: No CVE-ID: None
 [2007-07-01 21:26 UTC] ozone at cname dot com
Description:
------------
Documentation states that the __call() method will be passed two arguments, the first being the name of the called method, the second being *an array* of the arguments. Thus, when daisy-chaining the __call() method via parent::__call() or equivalent, the second __call() should have an array with a single element which is an array of the arguments passed to the first __call().

The actual behavior is more desirable than the documented behavior, and this is probably "not a bug". That said, I don't want to rewrite my code if a future version of PHP changes the behavior without warning.


Reproduce code:
---------------
class a {
        function __call($m, $a) {
                echo "--- a::$m\n";
                echo "call($m) ";
                var_dump($a);
        }
}

class b extends a {
        function __call($m, $a) {
                echo "--- b::$m\n";
                if($m == "special") {
                        echo "special override ";
                        var_dump($a);
                } else parent::__call($m, $a);
        }
}

$ca = new a();
$cb = new b();
$ca->test();
$ca->test("one", "two");
$cb->special();
$cb->test();
$cb->test("one", "two");


Expected result:
----------------
A literal interpretation of the documentation says the var_dump ultimately executed by the last call to $cb->test() "should" display something like:

array(1) {
  [0]=> array(2) {
      [0]=>
      string(3) "one"
      [1]=>
      string(3) "two"
  }
}


Actual result:
--------------
array(2) {
  [0]=>
  string(3) "one"
  [1]=>
  string(3) "two"
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-16 13:15 UTC] vrana@php.net
You are calling __call() directly. Documentation describes behavior with indirect calling - method($parameters).
 [2007-08-16 23:51 UTC] ozone at cname dot com
Examples of daisy-chaining parent:: are given in the documentation for "Constructors and Destructors", but not in the documentation for "Overloading", so I ended up writing code to see what would happen. If the rules about argument passing are different inside Magic Methods than elsewhere, it would be a useful thing to document.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Aug 13 22:00:03 2025 UTC