jd2007 Posted October 27, 2007 Share Posted October 27, 2007 // example function function ($a, $b, $c, $d, $e) { } will this increase its speed to load ? ----------- another question, do i need to create a function when assigning variables, e.g. below which one is quicker ? the example 1 or 2... example 1 class abc { protected $x; protected $y; function helloa($x, $y) { $this->x = $x; $this->y = $y; echo $x."&".$y; } function hellob($x, $y) { $this->x = $x; $this->y = $y; echo $x."%".$y; } } example2 class abc { protected $x; protected $y; function assign() { $this->x = $x; $this->y = $y; } function helloa($x, $y) { $this->assign(); echo $x."&".$y; } function hellob($x, $y) { $this->assign(); echo $x."%".$y; } } Quote Link to comment https://forums.phpfreaks.com/topic/74993-is-it-ok-for-a-function-to-have-many-argument-for-eg-5-eg-below/ Share on other sites More sharing options...
MadTechie Posted October 27, 2007 Share Posted October 27, 2007 not really.. what are you passing to it ? if your passing the same data to many functions then use OOP Quote Link to comment https://forums.phpfreaks.com/topic/74993-is-it-ok-for-a-function-to-have-many-argument-for-eg-5-eg-below/#findComment-379238 Share on other sites More sharing options...
toplay Posted October 27, 2007 Share Posted October 27, 2007 Don't worry about speed as it relates to number of arguments. I think about five/six individual arguments should be the limit, more than that leads to possible errors of what goes where. With large number of values that need to be passed to functions/methods, use objects or arrays. Quote Link to comment https://forums.phpfreaks.com/topic/74993-is-it-ok-for-a-function-to-have-many-argument-for-eg-5-eg-below/#findComment-379241 Share on other sites More sharing options...
jd2007 Posted October 27, 2007 Author Share Posted October 27, 2007 another question, do i need to create a function when assigning variables, e.g. below which one is quicker ? the example 1 or 2... example 1 class abc { protected $x; protected $y; function helloa($x, $y) { $this->x = $x; $this->y = $y; echo $x."&".$y; } function hellob($x, $y) { $this->x = $x; $this->y = $y; echo $x."%".$y; } } example2 class abc { protected $x; protected $y; function assign() { $this->x = $x; $this->y = $y; } function helloa($x, $y) { $this->assign(); echo $x."&".$y; } function hellob($x, $y) { $this->assign(); echo $x."%".$y; } } Quote Link to comment https://forums.phpfreaks.com/topic/74993-is-it-ok-for-a-function-to-have-many-argument-for-eg-5-eg-below/#findComment-379247 Share on other sites More sharing options...
MadTechie Posted October 27, 2007 Share Posted October 27, 2007 example 1 as example 2 isn't passing anything! Quote Link to comment https://forums.phpfreaks.com/topic/74993-is-it-ok-for-a-function-to-have-many-argument-for-eg-5-eg-below/#findComment-379249 Share on other sites More sharing options...
jd2007 Posted October 27, 2007 Author Share Posted October 27, 2007 sorry, e.g 2 was a mistake class abc { protected $x; protected $y; function assign($var1, $var2) { $this->x = $var1; $this->y = $var2; } function helloa($x, $y) { $this->assign($x, $y); echo $x."&".$y; } function hellob($x, $y) { $this->assign($x, $y); echo $x."%".$y; } } Quote Link to comment https://forums.phpfreaks.com/topic/74993-is-it-ok-for-a-function-to-have-many-argument-for-eg-5-eg-below/#findComment-379252 Share on other sites More sharing options...
MadTechie Posted October 27, 2007 Share Posted October 27, 2007 still example 1, Quote Link to comment https://forums.phpfreaks.com/topic/74993-is-it-ok-for-a-function-to-have-many-argument-for-eg-5-eg-below/#findComment-379255 Share on other sites More sharing options...
jd2007 Posted October 28, 2007 Author Share Posted October 28, 2007 why ? Quote Link to comment https://forums.phpfreaks.com/topic/74993-is-it-ok-for-a-function-to-have-many-argument-for-eg-5-eg-below/#findComment-379773 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.