Welcome Guest, Not a member yet? Register   Sign In
coding practice question
#1

[eluser]ixxalnxxi[/eluser]
I have a function that has a parameter. There are times when I call that function with nothing to send as a parameter. Would it be better for me to set up default parameters in the function,

function myFunc($var1 = '', $var2 = 0)

or should I simply leave the the function like this,

function myFunc($var1, $var2)

and not pass anything when I don't want any values sent in?
#2

[eluser]OwanH[/eluser]
Hey, this is really a PHP question rather than a CodeIgniter question. Assign default values to the parameters. If you leave the function definition without default parameter values then you MUST pass the values as arguments when calling the function. If you don't then a PHP error will be generated.

Merry Xmas, Happy Holidays, Happy New Year, and all the best with your PHP and CodeIgniter development Smile.




Theme © iAndrew 2016 - Forum software by © MyBB