limits to functions?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

limits to functions?

Post by SmokyBarnable »

Is there a limit to how many variables can be passed to a function?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

Post by SmokyBarnable »

:)
I didn't know you could call a function from within the same function....weird.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

Post by SmokyBarnable »

so call_user_func_array doesn't call a function?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

call_user_func_array() isn't called inside a function in volka's example.
User avatar
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

Post by SmokyBarnable »

could it be?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
omidkamangar
Forum Newbie
Posts: 16
Joined: Sun Jul 30, 2006 2:51 pm

Post 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.
Post Reply