php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69861 Callable fields are treated as magic __call()
Submitted: 2015-06-17 11:55 UTC Modified: 2015-06-17 13:09 UTC
From: php at developerjack dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.0.0alpha1 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at developerjack dot com
New email:
PHP Version: OS:

 

 [2015-06-17 11:55 UTC] php at developerjack dot com
Description:
------------
If a class has a magic __call() method, fields which are closure are not invoked.

The result being that the $args param to __call() exceeds memory limits due to nesting recursively (and, depending on recursion and memory limits does not report as a recursion limit reached).

On preliminary review, this may be related to the callable types and Classname::method() syntax:
https://github.com/php/php-src/commit/989a13608b5154672e6ab94f970e271f7d0ae502

Test script:
---------------
<?php
class CallableStub {
    protected $callback = null;
    public function setCallback(callable $callback) {
        $this->callback = $callback;
    }
    public function __call($name, $args) {
        if($this->callback == null || !is_callable($this->callback)) {
            throw new \LogicException("CallableStub requires a callback function to be callable.");
        }

        //$cb = $this->callback; // $cb(); use a locl variable instead and it works!
        return $this->callback($name, $args);
    }
} 

$s = new CallableStub();
$s->setCallback( function ($x, $y) { var_dump(func_get_args()); });
$s->frankfurt('rabbit stew');

Expected result:
----------------
--- expected ---
$this->callback($someArgs);// invoke the closure in $this->callback;


Actual result:
--------------
--- actual ---
$this->callback($someargs);// invokes __call('callback', [$someargs]);

Error:

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 262144 bytes) in /in/cg4kJ on line 16

Process exited with code 255.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-17 11:58 UTC] php at developerjack dot com
A copy of the bug report in 3v4l.org - I found this useful to debug and play with to reproduce.
http://3v4l.org/gQHkU
 [2015-06-17 13:09 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2015-06-17 13:09 UTC] laruence@php.net
use instead ($this->callback)($name, $args)
$this->callback means a method call..
($this->callback)() means a property value as callable

also take a look at this:

<?php
class A {
    public $test = NULL;
    function test() {
        var_dump(__METHOD__);
    }
}

$a = new A();

$a->test = function() {
    var_dump(__FUNCTION__);
};

$a->test();
($a->test)();

thanks
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 15:01:28 2024 UTC