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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alexander dot moldova at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 07 15:01:28 2024 UTC