Page 1 of 1

limits to functions?

Posted: Sat Apr 21, 2007 10:27 pm
by SmokyBarnable
Is there a limit to how many variables can be passed to a function?

Posted: Sat Apr 21, 2007 10:34 pm
by volka
There probably is but it shouldn't be a problem

Code: Select all

<?php
function foo() {
	$params = func_get_args();
	echo count($params), "\n";
}

for($e=1; $e<6; $e+=1) {
	$params = range(1, pow(10, $e));
	call_user_func_array('foo', $params);
}
?>
10
100
1000
10000
100000
Call it lack of imagination but I can't think of a well-designed function that takes a hundred thousand parameters.

Posted: Sat Apr 21, 2007 10:39 pm
by SmokyBarnable
:)
I didn't know you could call a function from within the same function....weird.

Posted: Sat Apr 21, 2007 11:00 pm
by volka
SmokyBarnable wrote::)
I didn't know you could call a function from within the same function....weird.
even weirder there's no such thing in the example.

Posted: Sat Apr 21, 2007 11:38 pm
by SmokyBarnable
so call_user_func_array doesn't call a function?

Posted: Sun Apr 22, 2007 1:07 am
by feyd
call_user_func_array() isn't called inside a function in volka's example.

Posted: Sun Apr 22, 2007 1:10 am
by SmokyBarnable
could it be?

Posted: Sun Apr 22, 2007 4:44 am
by Chris Corbyn
Yes, of course it could ;) PHP will do what you tell it to do. You can do anything inside a function that you could do outside the function. And yes, you can call foo() from within itself. It's called recursion :)

Posted: Sun Apr 22, 2007 7:59 am
by feyd
d11wtq wrote:It's called recursion :)
And if you're not careful, can net you some hot water.

Unless you know what you're doing, try to stay away from recursion.

Posted: Sun Apr 22, 2007 8:46 am
by omidkamangar
feyd wrote:
d11wtq wrote:It's called recursion :)
And if you're not careful, can net you some hot water.

Unless you know what you're doing, try to stay away from recursion.
recursion can be very useful if used properly and very dangerous if not.