Re: Calling Functions without all the arguments
| From: | Rasmus Lerdorf | Date: | Fri, 13 Apr 2001 14:53:49 +0000 |
| Subject: | Re: Calling Functions without all the arguments | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-48450@lists.php.net to get a copy of this message | ||
If a function has not been defined to take optional arguments, then you
*must* provide these arguments when you call the function. The fact that
previous versions of PHP incorrectly let you do this was at best an
undocumented misfeature, but more likely a bug.
And yes, having optional arguments with the default value defined in the
function definition is perfectly acceptable.
-Rasmus
On Sat, 14 Apr 2001, Chris Aitken wrote:
> On Fri, 13 Apr 2001, Hardy Merrill wrote:
>
> >I found the same problem - when we upgraded to PHP4, function calls
> >that used to work and NOT provide all the parameters, started failing.
> >
> >The way I fixed it was to give each parameter a default value *IN*
> >the function definition, like:
> >
> >function abc($a='', $b='') // assigns null as parameter defaults
> >
> >that way, every parameter gets a value, even if all the parameters
> >were not supplied in the call.
> >
>
> This works great (thanks for that :). However my question now is, what is
> the general opinion about how to handle this.
>
> Is it better to call functions giving all arguments values (even if its an
> empty "" value) or is it fine to assign values from within the function as
> described above ?