473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

call_user_func_array vs $myfunction( &$params )


Hi,

I was looking at
http://www.php.net/manual/en/functio...func-array.php and I
was wondering...

Given,
// --
function foo( &$params)
{
echo 'bar';
}
// --

What is the difference between

// --
$params = array( $stuff);
$myFn = 'foo';
$myFn($params)
// --

And

// --
$params = array( $stuff);
$myFn = 'foo';
call_user_func_array( $myFn, $params );
// --

Wont they both achieve the same result?

FFMG
--

'webmaster forum' (http://www.httppoint.com) | 'Free Blogs'
(http://www.journalhome.com/) | 'webmaster Directory'
(http://www.webhostshunter.com/)
'Recreation Vehicle insurance'
(http://www.insurance-owl.com/other/car_rec.php) | 'Free URL
redirection service' (http://urlkick.com/)
------------------------------------------------------------------------
FFMG's Profile: http://www.httppoint.com/member.php?userid=580
View this thread: http://www.httppoint.com/showthread.php?t=18946

Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing).

Aug 1 '07 #1
2 2532
On 01.08.2007 10:11 FFMG wrote:
What is the difference between

// --
$params = array( $stuff);
$myFn = 'foo';
$myFn($params)
// --

And

// --
$params = array( $stuff);
$myFn = 'foo';
call_user_func_array( $myFn, $params );
// --

Wont they both achieve the same result?
call_user_func_array is useful when the number of parameters to a called
function is variable or unknown, for example:

function nice_dump() {
$params = func_get_args();
echo "<pre>";
call_user_func_array('var_dump', $params);
echo "</pre>";
}

nice_dump(1, 2, 3);

--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Aug 1 '07 #2
Rik
On Wed, 01 Aug 2007 11:04:23 +0200, gosha bine <st********@gmail.com
wrote:
On 01.08.2007 10:11 FFMG wrote:
>What is the difference between
// -- $params = array( $stuff);
$myFn = 'foo';
$myFn($params)
// -- And // -- $params = array( $stuff);
$myFn = 'foo';
call_user_func_array( $myFn, $params );
// -- Wont they both achieve the same result?

call_user_func_array is useful when the number of parameters to a called
function is variable or unknown, for example:

function nice_dump() {
$params = func_get_args();
echo "<pre>";
call_user_func_array('var_dump', $params);
echo "</pre>";
}

nice_dump(1, 2, 3);
Indeed, it's not really function name that's interesting in this
particular example, it's the parameters that particular piece of code
doesn't have to worry about.

Then again, one of it's major advantages is it also supports callbacks, so
you can easily give a class function or object method to it. Your code
would be rather complex to get that otherwise...
--
Rik Wasmus
Aug 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: christopher vogt | last post by:
Hi, i'm wondering if there is something like $this-> to call a method inside another method of the same class without using the classname in front. I actually use class TEST { function...
7
by: Roman Töngi | last post by:
When I declare a function prototype in a header-file, have I to include this header-file in the implemenation file? Example: //main #include "myfunction.h" int main() { myFunction(); return...
18
by: Frances Del Rio | last post by:
this code is supposed to flip imgs at intervals of one second, but it flipps them much faster, it seems it flips them all in that first second, the more seconds the faster it flips them, instead of...
3
by: mra | last post by:
I want to cast an object that I have created from a typename to the corresponding type. Can anycone tell me how to do this? Example: //Here, Create the object of type "MyClass" object...
1
by: lwhitb1 | last post by:
I have been trying to load a javascript function from the body onload html tag, but I only want the function to load the first time the page is loaded: I have investigated but haven't found...
8
by: dvnsatish | last post by:
Hi does the below structure variable access declaration correct..does it retrieve the value of var if I kept struct var in bracket..let me know please if(*(str_src->var) !='') { //do some...
2
by: dhtmlkitchen | last post by:
I'm trying to learn something about JScript engine. I have the following example: <script>(function() { poop = "brown"; myFunction = function myFunction() {}
1
by: shivasusan | last post by:
Hi Friends! Please Help me! How i can solve this error? Please explain me, what is the error and how to solve? Error Type: ADODB.Recordset (0x800A0E7D) The connection cannot be used to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.