php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63857 calling closure when providing it as an arg from the args array
Submitted: 2012-12-26 15:32 UTC Modified: 2012-12-26 15:56 UTC
From: alexander dot moldova at gmail dot com Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 5.4.10 OS: ubuntu 12.10
Private report: No CVE-ID: None
 [2012-12-26 15:32 UTC] alexander dot moldova at gmail dot com
Description:
------------
calling closure when providing it as an arg from the args array provided as the 
second parameter for the invokeArgs method from \ReflectionMethod class

Test script:
---------------
method is:
public function simpleTest($a, callable $b, array $c)
    {
        return (int) call_user_func_array($b, $c) + $a;
    }

$params is:
array (size=3)
  0 => int 2
  1 => 
    object(Closure)[95]
  2 => 
    array (size=1)
      0 => int 2

and calling:
 $this->refl->invokeArgs(new Blablabla, $params);

will generate the bug

Expected result:
----------------
method returning value

Actual result:
--------------
Error: Argument 1 passed to {closure}() must be of the type array, integer given

In fact instead or the array is provided the "int 2"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-26 15:50 UTC] reeze@php.net
-Status: Open +Status: Not a bug
 [2012-12-26 15:50 UTC] reeze@php.net
From the error message, the closure declared like: function(array $param);

see http://php.net/call_user_func_array

so : 
call_user_func_array($b, $c) + $a;  <=> call_user_func_array($b, array(2)) + 0;
and   <=> $closure(2);

2 is not an array
 [2012-12-26 15:56 UTC] alexander dot moldova at gmail dot com
yeap, i've already realized, thanks )
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Apr 08 06:01:25 2020 UTC