Re: [RFC] skipping optional parameters
| From: | Yasuo Ohgaki | Date: | Tue, 17 Apr 2012 23:55:17 +0000 |
| Subject: | Re: [RFC] skipping optional parameters | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-60138@lists.php.net to get a copy of this message | ||
Hi,
2012/4/18 Simon J Welsh <simon@welsh.co.nz>:
> On 18/04/2012, at 10:54 AM, Stas Malyshev wrote:
>
>> Hi!
>>
>> One of the annoying things I've encountered in working with PHP was
>> dealing with functions having long optional parameter lists, especially
>> if you need to change only the last one - you have to copy all the
>> defaults. Full named params implementation would solve it, probably, but
>> before we have that here's an easier solution for part of the problem:
>>
>> https://wiki.php.net/rfc/skipparams
>>
>> Basically, it allows you to do this:
>>
>> create_query("deleted=0", "name",,, /*report_errors*/ true);
>>
>> Implementation of it is here:
>> https://github.com/smalyshev/php-src/tree/skip_params
>> All things described in RFC seem to be working, please tell me if I
>> forgot anything. If it's accepted I'll also add tests, etc. of course.
>
>
> Hi
>
> I like this proposal. One thing pops out at me though.
>
> Since func_num_args() won't be able to be used to see if an argument is set, could a
> func_isset_arg() be added? So something like:
> if(func_num_args() > 2) $value = func_get_arg(2);
> would become:
> if(func_isset_arg(2)) $value = func_get_arg(2);
Good point.
For func_get_arg(), having "undefined" is mandatory,
otherwise we cannot tell if it is defined or not.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net