php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #26585 Right way to pass parameters to call_user_func_array
Submitted: 2003-12-10 11:01 UTC Modified: 2003-12-10 11:11 UTC
From: jsabater at linuxsilo dot net Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 4.3.3 OS: Linux
Private report: No CVE-ID: None
 [2003-12-10 11:01 UTC] jsabater at linuxsilo dot net
Description:
------------
When calling a defined function like this:

call_user_func_array ('myfunc', $myarray);

The $myarray array only contains the first value, but not the whole array. For instance:

function myfunc ($myarray)
{
  if (is_array($myarray)) print("It's an array");
  else print ("It's not an array");
}

call_user_func_array ('myfunc', array ("first", "second", "third"));

Then you would receive the message "It's not an array". If you print_r the array, then you would only get "first".

Then, if you change the call to this:

call_user_func_array ('myfunc', array (array ("first", "second", "third")));

It works as expected. So, the documentation available at http://es.php.net/manual/en/function.call-user-func-array.php seems to be wrong.

Thanks for your time. Hope this helps.

Reproduce code:
---------------
function myfunc ($myarray)
{
  if (is_array($myarray)) print("It's an array");
  else print ("It's not an array");
}

call_user_func_array ('myfunc', array ("first", "second", "third"));

Expected result:
----------------
It's an array

Actual result:
--------------
It's not an array

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-12-10 11:12 UTC] vrana@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Second parameter of call_user_func_array() is an array of parameters. Thus you have to call:

call_user_func_array ('myfunc', array(array ("first", "second", "third")));

to get expected result.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 30 17:01:30 2024 UTC