[RFC] Skipping parameters take 2

php.internals

Stas Malyshev

12 years ago
Hi! I've finally took some time to revive the skipping parameter RFC and patch. For those who doesn't remember what it is please see: https://wiki.php.net/rfc/skipparams TLDR version: The idea is to allow skipping parameters in function with optional arguments so that this: function create_query($where, $order_by, $join_type='INNER', $execute = false, $report_errors = true) can be called like this: create_query("deleted=0", "name", default, default, /*report_errors*/ true); Instead of trying to remember what the defaults are. The patch is here: https://github.com/php/php-src/pull/426 Any comments or feedback on the RFCs and the code are welcome, especially pointing out the cases where it may not work (which means we need more phpt's there :)
-- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

Laruence

12 years ago
On Mon, Sep 2, 2013 at 3:17 PM, Stas Malyshev <smalyshev@sugarcrm.com> wrote:
> Hi! > > I've finally took some time to revive the skipping parameter RFC and > patch. For those who doesn't remember what it is please see: > https://wiki.php.net/rfc/skipparams > TLDR version: > > The idea is to allow skipping parameters in function with optional > arguments so that this: > function create_query($where, $order_by, $join_type='INNER', $execute > = false, $report_errors = true) > > can be called like this: > create_query("deleted=0", "name", default, default, > /*report_errors*/ true); >
Hey: I am not sure whether this is a little overhead. but if we do want this. to be honest, I even prefer leave it empty to "default". like create_query("delete=0", "name", , , true); thanks
> Instead of trying to remember what the defaults are. > The patch is here: > > https://github.com/php/php-src/pull/426 > > Any comments or feedback on the RFCs and the code are welcome, > especially pointing out the cases where it may not work (which means we > need more phpt's there :) > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >
-- Laruence Xinchen Hui http://www.laruence.com/

Stas Malyshev

12 years ago
Hi!
> I am not sure whether this is a little overhead. > > but if we do want this. to be honest, I even prefer leave it empty to > "default". > > like create_query("delete=0", "name", , , true);
That's how it was initially, and I was convinced default is better. So I don't think I'm going back to empty. default indeed seems to be more readable (try to visually distinguish between ,,,, and ,,,, - if you have a lot of code, it won't be that easy). It is more verbose, but PHP never attempted to be "save the bytes" language.
-- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

Florin Razvan Patan

12 years ago
On Mon, Sep 2, 2013 at 9:41 AM, Stas Malyshev <smalyshev@sugarcrm.com> wrote:
> Hi! > >> I am not sure whether this is a little overhead. >> >> but if we do want this. to be honest, I even prefer leave it empty to >> "default". >> >> like create_query("delete=0", "name", , , true); > > That's how it was initially, and I was convinced default is better. So I > don't think I'm going back to empty. default indeed seems to be more > readable (try to visually distinguish between ,,,, and ,,,, - if you > have a lot of code, it won't be that easy). It is more verbose, but PHP > never attempted to be "save the bytes" language. > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >
Hi, For me as a user it would make much more sense to have named parameters then typing default. Default also feels a bit strange to type. What if I miss one default in the line? Or in the other proposal here, what if I miss one comma? Named parameters would also solve a problem from another RFC that's being proposed right now if I understand correctly so why not go for that? Kind regards ---- Florin Patan https://github.com/dlsniper http://www.linkedin.com/in/florinpatan

Ferenc Kovacs

12 years ago
On Mon, Sep 2, 2013 at 9:41 AM, Stas Malyshev <smalyshev@sugarcrm.com>wrote:
> Hi! > > > I am not sure whether this is a little overhead. > > > > but if we do want this. to be honest, I even prefer leave it empty to > > "default". > > > > like create_query("delete=0", "name", , , true); > > That's how it was initially, and I was convinced default is better. So I > don't think I'm going back to empty. default indeed seems to be more > readable (try to visually distinguish between ,,,, and ,,,, - if you > have a lot of code, it won't be that easy). It is more verbose, but PHP > never attempted to be "save the bytes" language. > >
another small advantage would be that IDEs could show you the default value for the argument when hovering the default keyword.
-- Ferenc Kovács @Tyr43l - http://tyrael.hu

Lester Caine

12 years ago
Ferenc Kovacs wrote:
> another small advantage would be that IDEs could show you the default value > for the argument when hovering the default keyword.
But a good IDE is already showing the full function and notes ... and will autocomplete so that this fix is not actually required :) In many cases, the 'additions' being loaded into the core would be much better handled in an IDE and already were in am ore flexible way ...
-- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

Jannik Zschiesche

12 years ago
Am Montag, 2. September 2013 um 11:02 schrieb Lester Caine:
> Ferenc Kovacs wrote: > > another small advantage would be that IDEs could show you the default value > > for the argument when hovering the default keyword. > > > > But a good IDE is already showing the full function and notes ... and will > autocomplete so that this fix is not actually required :) > > In many cases, the 'additions' being loaded into the core would be much better > handled in an IDE and already were in am ore flexible way ... > > >
Except for the case when the default changes. With `default` you will to the new default, with a (once) generated code block in the IDE it will stay the old default. And exactly this is the actual intention of this proposal (as far as I understood it).
-- Cheers Jannik

Lester Caine

12 years ago
Jannik Zschiesche wrote:
>>> another small advantage would be that IDEs could show you the default value >>> for the argument when hovering the default keyword. >> But a good IDE is already showing the full function and notes ... and will >> autocomplete so that this fix is not actually required :) >> >> In many cases, the 'additions' being loaded into the core would be much better >> handled in an IDE and already were in am ore flexible way ... > > Except for the case when the default changes. > With `default` you will to the new default, with a (once) generated code block > in the IDE it will stay the old default. > > And exactly this is the actual intention of this proposal (as far as I > understood it).
? ... How would the default change from what is defined in the code? What am I missing?
-- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

Ferenc Kovacs

12 years ago
On Mon, Sep 2, 2013 at 12:24 PM, Lester Caine <lester@lsces.co.uk> wrote:
> Jannik Zschiesche wrote: > >> another small advantage would be that IDEs could show you the default >>>> value >>>> for the argument when hovering the default keyword. >>>> >>> But a good IDE is already showing the full function and notes ... and >>> will >>> autocomplete so that this fix is not actually required :) >>> >>> In many cases, the 'additions' being loaded into the core would be much >>> better >>> handled in an IDE and already were in am ore flexible way ... >>> >> >> Except for the case when the default changes. >> With `default` you will to the new default, with a (once) generated code >> block >> in the IDE it will stay the old default. >> >> And exactly this is the actual intention of this proposal (as far as I >> understood it). >> > > ? ... How would the default change from what is defined in the code? > What am I missing? > >
you write your code where you copypaste the default value some time passes somebody changes the default value in the called function definition your code now calls the function with a non-default value.
-- Ferenc Kovács @Tyr43l - http://tyrael.hu

Lester Caine

12 years ago
Ferenc Kovacs wrote:
> > you write your code where you copypaste the default value > some time passes > somebody changes the default value in the called function definition > your code now calls the function with a non-default value.
Actually THAT is a problem I've hit in reverse! Some bugger changing the default in a library without understanding the consequences! In which case the fix was to put in the 'default' I wanted ... this works either way, but I could at least see in the IDE that the default had been changed so tracing it did not take as long as it could have.
-- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

Sebastian Krebs

12 years ago
2013/9/2 Lester Caine <lester@lsces.co.uk>
> Ferenc Kovacs wrote: > >> >> you write your code where you copypaste the default value >> some time passes >> somebody changes the default value in the called function definition >> your code now calls the function with a non-default value. >> > > Actually THAT is a problem I've hit in reverse! Some bugger changing the > default in a library without understanding the consequences! In which case > the fix was to put in the 'default' I wanted ... this works either way, but > I could at least see in the IDE that the default had been changed so > tracing it did not take as long as it could have.
But thats a problem no language (with default values for parameters of course) can help you, except you avoid default values in every case. I for myself always use "null" as default value, so I must say, that a special keyword doesn't bring me any benefit. In this meaning: The named parameters are more useful :) Regards, Sebastian
> > > -- > Lester Caine - G8HFL > ----------------------------- > Contact - http://lsces.co.uk/wiki/?page=**contact<http://lsces.co.uk/wiki/?page=contact> > L.S.Caine Electronic Services - http://lsces.co.uk > EnquirySolve - http://enquirysolve.com/ > Model Engineers Digital Workshop - http://medw.co.uk > Rainbow Digital Media - http://rainbowdigitalmedia.co.**uk<http://rainbowdigitalmedia.co.uk> > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
-- github.com/KingCrunch

Stas Malyshev

12 years ago
Hi!
> another small advantage would be that IDEs could show you the default > value for the argument when hovering the default keyword.
That actually would be excellent if they did it. I hope (if this is accepted) everybody does.
-- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

Nikita Popov

12 years ago
On Mon, Sep 2, 2013 at 9:17 AM, Stas Malyshev <smalyshev@sugarcrm.com>wrote:
> Hi! > > I've finally took some time to revive the skipping parameter RFC and > patch. For those who doesn't remember what it is please see: > https://wiki.php.net/rfc/skipparams > TLDR version: > > The idea is to allow skipping parameters in function with optional > arguments so that this: > function create_query($where, $order_by, $join_type='INNER', $execute > = false, $report_errors = true) > > can be called like this: > create_query("deleted=0", "name", default, default, > /*report_errors*/ true); > > Instead of trying to remember what the defaults are. > The patch is here: > > https://github.com/php/php-src/pull/426 > > Any comments or feedback on the RFCs and the code are welcome, > especially pointing out the cases where it may not work (which means we > need more phpt's there :) >
I'm -1 on this proposal. I think this doesn't really help readability. Right now you should implement functions with many options with an $options array. If we want to change something here, we should skip this step and go right for named arguments. I think I'll give implementing them a try. Nikita

Stas Malyshev

12 years ago
Hi!
> I think this doesn't really help readability. Right now you should > implement functions with many options with an $options array.
I don't understand. Who says I should do that? I certainly don't see how I should.
> If we want to change something here, we should skip this step and go > right for named arguments. I think I'll give implementing them a try.
If you are ready to present named args proposal for 5.6, fine. But if not, I think denying obviously requested feature (see links for requests in the RFC) because some "pie in the sky" consideration is completely wrong. I must say it seems a little strange for me given current stream of "because we can" syntax additions proposed to reject something that has been asked for by real people for years just because sometime in the future we might or might not have something that may do a similar thing in different way.
-- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

Levi Morrison

12 years ago
On Mon, Sep 2, 2013 at 2:11 PM, Stas Malyshev <smalyshev@sugarcrm.com>wrote:

Levi Morrison

12 years ago
Oops, didn't mean to send a blank message, sorry all. Just clicked on the wrong spot.

Madara Uchiha

12 years ago
I don't like it. Empty is how it's done on any language which allows this sort of thing, it's the most intuitive and I don't see anything wrong with it. If you need this, it probably means that your priorities are not set well in the function. And if you have a function that has multiple optional parameters in which the order does not matter, you don't want multiple optional parameters, you want one optional array, which would contain whatever it is that you want. Language constructs and syntax helpers aren't a substitute for well-written code and documentation. On Mon, Sep 2, 2013 at 11:48 PM, Levi Morrison <morrison.levi@gmail.com>wrote:

Robert Stoll

12 years ago
Hi Stanislav I would not agree with your argument that it should be introduced because it is requested by real people for years and it is simple to add. Isn't that pretty much the same as "because we can"? IMO we should wait with this RFC if Nikita is willing to write an RFC for named parameters including an implementation afterwards, because I think named parameters would address the problem way better. The skipping parameters as in your proposal would then just be the ugly alternative. However, if the RFC for named parameters will not be created or rejected, then I would appreciate your RFC. Best, Robert -----Ursprüngliche Nachricht----- Von: Stas Malyshev [mailto:smalyshev@sugarcrm.com] Gesendet: Montag, 2. September 2013 22:12 An: Nikita Popov Cc: PHP Internals Betreff: Re: [PHP-DEV] [RFC] Skipping parameters take 2 Hi!
> I think this doesn't really help readability. Right now you should > implement functions with many options with an $options array.
I don't understand. Who says I should do that? I certainly don't see how I should.
> If we want to change something here, we should skip this step and go > right for named arguments. I think I'll give implementing them a try.
If you are ready to present named args proposal for 5.6, fine. But if not, I think denying obviously requested feature (see links for requests in the RFC) because some "pie in the sky" consideration is completely wrong. I must say it seems a little strange for me given current stream of "because we can" syntax additions proposed to reject something that has been asked for by real people for years just because sometime in the future we might or might not have something that may do a similar thing in different way.
-- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

Stas Malyshev

12 years ago
Hi!
> I would not agree with your argument that it should be introduced because it > is requested by real people for years and it is simple to add. Isn't that > pretty much the same as "because we can"?
No, it is pretty much the opposite. It is "because people need it".
> IMO we should wait with this RFC if Nikita is willing to write an RFC for > named parameters including an implementation afterwards, because I think
We've been talking about it for years (last time here: https://wiki.php.net/rfc/namedparameters) but nothing happened. But I'm certainly willing to give it a chance, if it is happening. I just not want for all the effort to be wasted if it's not and we'd be left without a solution for a real problem again.
-- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

Sebastian Krebs

12 years ago
2013/9/2 Stas Malyshev <smalyshev@sugarcrm.com>
> Hi! > > > I would not agree with your argument that it should be introduced > because it > > is requested by real people for years and it is simple to add. Isn't that > > pretty much the same as "because we can"? > > No, it is pretty much the opposite. It is "because people need it". >
I am a user and I don't need it and named parameters makes it obsolete anyway. Now it would be interesting, if "people" would "need" named parameters less, than the ability to pass "default" instead of "null" (or whatever)....
> > > IMO we should wait with this RFC if Nikita is willing to write an RFC for > > named parameters including an implementation afterwards, because I think > > We've been talking about it for years (last time here: > https://wiki.php.net/rfc/namedparameters) but nothing happened. But I'm > certainly willing to give it a chance, if it is happening. I just not > want for all the effort to be wasted if it's not and we'd be left > without a solution for a real problem again. > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
-- github.com/KingCrunch

Nikita Popov

12 years ago
>>> I must say it seems a little strange for me given current stream of >>> "because we can" syntax additions proposed to reject something that has >>> been asked for by real people for years just because sometime in the >>> future we might or might not have something that may do a similar thing >>> in different way. >> >> I would not agree with your argument that it should be introduced
because it
>> is requested by real people for years and it is simple to add. Isn't that >> pretty much the same as "because we can"? > > No, it is pretty much the opposite. It is "because people need it".
lolwut, you're kidding right? So you listed a bunch of StackOverflow questions asking for this and from this concluded that this is a feature "people need" whereas the RFCs by ircmaxell/me (whichever you mean) are not needed and are proposed just "because we can" and are not needed by "real people"? Would you like RFC's to include detailed chat logs, Twitter mentions and Reddit conversations as proof that features are wanted by "real people"? Nikita

Derick Rethans

12 years ago
On Mon, 2 Sep 2013, Stas Malyshev wrote:
> Hi! > > I've finally took some time to revive the skipping parameter RFC and > patch. For those who doesn't remember what it is please see: > https://wiki.php.net/rfc/skipparams > TLDR version: > > The idea is to allow skipping parameters in function with optional > arguments so that this: > function create_query($where, $order_by, $join_type='INNER', $execute > = false, $report_errors = true) > > can be called like this: > create_query("deleted=0", "name", default, default, /*report_errors*/ true);
What would happen if I had done: define('default', 42); before that line? cheers, Derick
-- http://derickrethans.nl | http://xdebug.org Like Xdebug? Consider a donation: http://xdebug.org/donate.php twitter: @derickr and @xdebug Posted with an email client that doesn't mangle email: alpine

Johannes Schlueter

12 years ago
On Mon, 2013-09-02 at 11:48 +0100, Derick Rethans wrote:
> > can be called like this: > > create_query("deleted=0", "name", default, default, /*report_errors*/ true); > > What would happen if I had done: > > define('default', 42); > > before that line?
Nothing special as default is a keyword already (-> switch). Your only way to access that constant is already by using the constant() function. johannes

Etienne Kneuss

12 years ago
On Mon, Sep 2, 2013 at 12:48 PM, Derick Rethans <derick@php.net> wrote:
> On Mon, 2 Sep 2013, Stas Malyshev wrote: > > > Hi! > > > > I've finally took some time to revive the skipping parameter RFC and > > patch. For those who doesn't remember what it is please see: > > https://wiki.php.net/rfc/skipparams > > TLDR version: > > > > The idea is to allow skipping parameters in function with optional > > arguments so that this: > > function create_query($where, $order_by, $join_type='INNER', $execute > > = false, $report_errors = true) > > > > can be called like this: > > create_query("deleted=0", "name", default, default, > /*report_errors*/ true); > > What would happen if I had done: > > define('default', 42); > > before that line? >
well, default is a keyword so you wouldn't be able to use it as a constant like that. You would be able to define it via its string name, sure, but not access it directly.
> > cheers, > Derick > > -- > http://derickrethans.nl | http://xdebug.org > Like Xdebug? Consider a donation: http://xdebug.org/donate.php > twitter: @derickr and @xdebug > Posted with an email client that doesn't mangle email: alpine > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
-- Etienne Kneuss

Stas Malyshev

12 years ago
Hi!
> What would happen if I had done: > > define('default', 42); > > before that line?
Pretty much the same as if you did: define('if', 42); if($a == 1) print "one"; default is a keyword.
-- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

Pierre Joye

12 years ago
hi Stas, On Mon, Sep 2, 2013 at 9:17 AM, Stas Malyshev <smalyshev@sugarcrm.com> wrote:
> Hi! > > I've finally took some time to revive the skipping parameter RFC and > patch. For those who doesn't remember what it is please see: > https://wiki.php.net/rfc/skipparams > TLDR version: > > The idea is to allow skipping parameters in function with optional > arguments so that this: > function create_query($where, $order_by, $join_type='INNER', $execute > = false, $report_errors = true) > > can be called like this: > create_query("deleted=0", "name", default, default, > /*report_errors*/ true); > > Instead of trying to remember what the defaults are. > The patch is here: > > https://github.com/php/php-src/pull/426 > > Any comments or feedback on the RFCs and the code are welcome, > especially pointing out the cases where it may not work (which means we > need more phpt's there :)
Using default instead of ,,, is indeed much more readable. However I still wonder what prevents to finally implement named parameters too, it will provide the same feature while being even more handy and easier. I could dig the archives but I don't remember what was the reason why we rejected the idea back then. Cheers,
-- Pierre @pierrejoye | http://www.libgd.org

Sebastian Krebs

12 years ago
2013/9/2 Pierre Joye <pierre.php@gmail.com>
> hi Stas, > > On Mon, Sep 2, 2013 at 9:17 AM, Stas Malyshev <smalyshev@sugarcrm.com> > wrote: > > Hi! > > > > I've finally took some time to revive the skipping parameter RFC and > > patch. For those who doesn't remember what it is please see: > > https://wiki.php.net/rfc/skipparams > > TLDR version: > > > > The idea is to allow skipping parameters in function with optional > > arguments so that this: > > function create_query($where, $order_by, $join_type='INNER', $execute > > = false, $report_errors = true) > > > > can be called like this: > > create_query("deleted=0", "name", default, default, > > /*report_errors*/ true); > > > > Instead of trying to remember what the defaults are. > > The patch is here: > > > > https://github.com/php/php-src/pull/426 > > > > Any comments or feedback on the RFCs and the code are welcome, > > especially pointing out the cases where it may not work (which means we > > need more phpt's there :) > > Using default instead of ,,, is indeed much more readable. > > However I still wonder what prevents to finally implement named > parameters too, it will provide the same feature while being even more > handy and easier.
And it covers an additional use-case: Self-explaning parameters like in "foo(is_strict = false)" instead of "foo(null, null, false)".
> I could dig the archives but I don't remember what > was the reason why we rejected the idea back then. > > Cheers, > -- > Pierre > > @pierrejoye | http://www.libgd.org > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
-- github.com/KingCrunch

Jonathan Bond-Caron

12 years ago
On Mon Sep 2 08:52 AM, Sebastian Krebs wrote:
> 2013/9/2 Pierre Joye <pierre.php@gmail.com> > > > > > > > Any comments or feedback on the RFCs and the code are welcome, > > > especially pointing out the cases where it may not work (which means > > > we need more phpt's there :) > > > > Using default instead of ,,, is indeed much more readable. > > > > However I still wonder what prevents to finally implement named > > parameters too, it will provide the same feature while being even more > > handy and easier. > > > And it covers an additional use-case: Self-explaning parameters like in > "foo(is_strict = false)" instead of "foo(null, null, false)". > >
Lots of overlap between variadic functions, this proposal & named parameters. A popular use case for library authors is to use: interface foo { function formatUseCases(array $options); } - Advantage: No dependency on a class / object - Disadvantage: doesn't document what options are available, hard to extend 'default parameters' interface foo { function formatUseCases(MyOptions $options); } - Advantage: documents which options are available, easy to extend default parameters - Disadvantage: modification of the object means these 'options' are available to any declaration using it, hard to maintain over time without big refactoring (lots of options objects) interface foo { function formatUseCases(...$options); } - Advantage: No dependency on a class / object - Disadvantage: doesn't document what options are available, no default parameters interface foo { function formatUseCases($showGood = true, $showBad = true, $pretty = true, $title= "what are these parameters?"); } - Advantage: Self-documenting with default parameters - Disadvantage: Not extendable api signature (changing default parameters) - Readability: # array formatUseCases(['showGood': true, 'showBad': true, 'pretty': true]); #object $obj->showGood = true; $obj->showBad = true; $obj->pretty = true; formatUseCases($obj); # variadic or function declaration formatUseCases(true, true, true, "what are these parameters?"); - Solution somewhat as a hybrid? interface foo { function formatUseCases(...$options[showGood = true, showBad = true, pretty = true, title= "what are these parameters?"]); } formatUseCases(true, true, true, "use defaults for everything else"); formatUseCases(['title': "use defaults for everything else"]); // more readable Implemention wise $options could be ~ SplParameters which implements ArrayInterface : class bar implements foo { function formatUseCases(...$options[]) { // api signature as $options[] always accepted (uses default params) echo get_class($options); // SplParameters var_dump($options['showGood']) // true; var_dump($options->showGood) // true; } } class bar2 implements foo { function formatUseCases(...$options[showGood = false]) { // easy to extend default options var_dump($options['showGood']) // false; } } Why use special syntax ~ "...$options[]" instead of just named parameters: http://msdn.microsoft.com/en-us/library/dd264739.aspx My hunch is that applying named parameters to every function would be very costly in PHP. But as a special syntax applied to a few functions, this might work well.

Lazare Inepologlou

12 years ago
2013/9/2 jbondc@openmv.com <jbondc@openmv.com>
> On Mon Sep 2 08:52 AM, Sebastian Krebs wrote: > > 2013/9/2 Pierre Joye <pierre.php@gmail.com> > > > > > > > > > > Any comments or feedback on the RFCs and the code are welcome, > > > > especially pointing out the cases where it may not work (which means > > > > we need more phpt's there :) > > > > > > Using default instead of ,,, is indeed much more readable. > > > > > > However I still wonder what prevents to finally implement named > > > parameters too, it will provide the same feature while being even more > > > handy and easier. > > > > > > And it covers an additional use-case: Self-explaning parameters like in > > "foo(is_strict = false)" instead of "foo(null, null, false)". > > > > > > Lots of overlap between variadic functions, this proposal & named > parameters. > >
I don't think that variadic functions prevent any of the other two, or that they are used for the same cases.
> interface foo { > function formatUseCases(...$options); > } > - Advantage: No dependency on a class / object > - Disadvantage: doesn't document what options are available, no default > parameters >
This is totally not a use case for variadic functions. The arguments of a variadic function are indexed, not named. In addition, they have the same type (or at least they are treated the same way). Lazare INEPOLOGLOU Ingénieur Logiciel

Jonathan Bond-Caron

12 years ago
> > > interface foo { > > function formatUseCases(...$options); } > > - Advantage: No dependency on a class / object > > - Disadvantage: doesn't document what options are available, no > > default parameters > > > > > This is totally not a use case for variadic functions. The arguments of a > variadic function are indexed, not named. In addition, they have the same > type (or at least they are treated the same way). >
Right I'm for variadic '...$options' as proposed with indexed arguments (just like c). Python calls this positional arguments. I'm stretching the comparison to see if syntax could be augmented to serve another use case (with named arguments)? ...$options[] would be more similar to **keyparam in python: http://rosettacode.org/wiki/Named_Arguments#Python

Stas Malyshev

12 years ago
Hi!
> However I still wonder what prevents to finally implement named > parameters too, it will provide the same feature while being even more
For named params, you need to rewrite all args handling, since now it is a positional array and that doesn't work with named args. On the way you'd have to refactor zend_parse_parameters to understand named args (which aren't even named in many internals, so you'd have to add those) and deal with functions that use + and * in various creative ways and see how those can be reconciled with named params. And then of course is the question of by-ref parameters and how to make the syntax handle those too. Long story short, you'll have to rewrite everything that does with argument passing, argument receiving or even peeks into arguments. Skipping parameters is relatively simple - you just put NULL and fix tons of functions which don't use defaults properly (will need to be done on a larger scale with named params too, because named params means you can skip args).
> handy and easier. I could dig the archives but I don't remember what > was the reason why we rejected the idea back then.
Bikeshedding about the syntax mostly, but that all pales compared to amount of work that needs to be done in the engine to support named params. Unless, of course, I'm completely wrong and there's an easy way to do it, which I am totally missing - in which case please point it out.
-- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

Nikita Popov

12 years ago
On Mon, Sep 2, 2013 at 10:19 PM, Stas Malyshev <smalyshev@sugarcrm.com>wrote:
> Hi! > > > However I still wonder what prevents to finally implement named > > parameters too, it will provide the same feature while being even more > > For named params, you need to rewrite all args handling, since now it is > a positional array and that doesn't work with named args. On the way > you'd have to refactor zend_parse_parameters to understand named args > (which aren't even named in many internals, so you'd have to add those) > and deal with functions that use + and * in various creative ways and > see how those can be reconciled with named params. And then of course is > the question of by-ref parameters and how to make the syntax handle > those too. Long story short, you'll have to rewrite everything that does > with argument passing, argument receiving or even peeks into arguments. >
I already have a mostly-working implementation for named arguments and unless I missed something critical it does not require us to redo argument passing. The idea I followed was to keep the argument passing pretty much as-is, just instead of always pushing on top of the stack to place named args directly at the correct offsets. So we still have a stack of positional arguments, they're just inserted out of order. This will also leave NULL values in between, so they need to be handled as in your implementation. The only thing you can't handle this way are named arguments that are not defined in the signature - if we want something like pythons **kwargs those need to be collected in an HT. I'd likely not support that at first, land basic named args instead and then seek to merge kwargs into the RFC's for variadics/unpacking. Nikita

Stas Malyshev

12 years ago
Hi!
> I already have a mostly-working implementation for named arguments and > unless I missed something critical it does not require us to redo > argument passing. The idea I followed was to keep the argument passing > pretty much as-is, just instead of always pushing on top of the stack to > place named args directly at the correct offsets. So we still have a > stack of positional arguments, they're just inserted out of order. This > will also leave NULL values in between, so they need to be handled as in > your implementation. The only thing you can't handle this way are named
That may work and actually except for the syntax for default pretty much matches what my patch does completely. However what to do with internal functions, especially those using + and *? Not all of them have proper arginfos, and some of them would be pretty hard to describe properly - something like array_intersect_uassoc() for example. Current arginfo for it is completely misleading.
> arguments that are not defined in the signature - if we want something > like pythons **kwargs those need to be collected in an HT. I'd likely
This however is a question. **kwargs is super-ugly, and the fact that python has 2 sets of optional argument was always annoying for me. We should try to avoid it. Varargs syntax may actually be better there, but the question is where would we keep the names? Would additional hash table arg be on the stack? Wouldn't it clash with how proposed varargs work? Also, what about internals - how the engine knows names of the arguments there?
> not support that at first, land basic named args instead and then seek > to merge kwargs into the RFC's for variadics/unpacking.
Not supporting this means basically it doesn't solve the problem with options lists, which it is supposed to be the solution for. Also, it's not clear what func_get_args and all other inspection functions would do in such case. Of course, if you drop option lists and allow only pre-defined arguments the task becomes much easier, I agree, but also much less useful for things that **kwargs and such are used.
-- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

Nikita Popov

12 years ago
On Tue, Sep 3, 2013 at 12:00 AM, Stas Malyshev <smalyshev@sugarcrm.com>wrote:
> Hi! > > > I already have a mostly-working implementation for named arguments and > > unless I missed something critical it does not require us to redo > > argument passing. The idea I followed was to keep the argument passing > > pretty much as-is, just instead of always pushing on top of the stack to > > place named args directly at the correct offsets. So we still have a > > stack of positional arguments, they're just inserted out of order. This > > will also leave NULL values in between, so they need to be handled as in > > your implementation. The only thing you can't handle this way are named > > That may work and actually except for the syntax for default pretty much > matches what my patch does completely. However what to do with internal > functions, especially those using + and *? Not all of them have proper > arginfos, and some of them would be pretty hard to describe properly - > something like array_intersect_uassoc() for example. Current arginfo for > it is completely misleading. >
I think at some point you just need to go for "good enough" rather than "optimal support for everything". If we don't support the rather special case of internal functions having variadic arguments followed by fixed ones, I wouldn't consider that too tragic.
> > arguments that are not defined in the signature - if we want something > > like pythons **kwargs those need to be collected in an HT. I'd likely > > This however is a question. **kwargs is super-ugly, and the fact that > python has 2 sets of optional argument was always annoying for me. We > should try to avoid it. Varargs syntax may actually be better there,
Yes, this is likely better in PHP's context. After all our array structure supports both continuous arrays (for normal varargs) and dictionaries (for kwargs), so I think we should be able to combine those.
> but the question is where would we keep the names? Would additional hash > table arg be on the stack?
Might be simpler to pass it via function_state.
> Also, what about internals - how the engine knows names of the > arguments there? >
What do you mean by this?
> not support that at first, land basic named args instead and then seek > > to merge kwargs into the RFC's for variadics/unpacking. > > Not supporting this means basically it doesn't solve the problem with > options lists, which it is supposed to be the solution for. Also, it's > not clear what func_get_args and all other inspection functions would do > in such case. Of course, if you drop option lists and allow only > pre-defined arguments the task becomes much easier, I agree, but also > much less useful for things that **kwargs and such are used. >
I think the main use of named args is in specifying existing arguments out of order. kwargs is a nice addition for minor use cases. I'll think about how to support those a bit more. Nikita

Stas Malyshev

12 years ago
Hi!
> I think at some point you just need to go for "good enough" rather than > "optimal support for everything". If we don't support the rather special
I am all for that. If only I wasn't this very minute bashed by several other people for not accounting for every exotic use case and not proposing optimal support for everything but just good enough for most practical use cases...
> case of internal functions having variadic arguments followed by fixed > ones, I wouldn't consider that too tragic.
It's not only this case, we have a number of internal functions that do weird things with their arguments. What "don't support" would mean in this case?
> Also, what about internals - how the engine knows names of the > arguments there? > > > What do you mean by this?
Internal functions. Some of them have arginfos which bear only passing resemblance with what these functions actually do.
> I think the main use of named args is in specifying existing arguments > out of order. kwargs is a nice addition for minor use cases. I'll think > about how to support those a bit more.
Option lists are everywhere, if you look at any framework everybody does it. Of course, now they do it with option arrays, and if we accept that option arrays are good then we don't need varargs either. But I thought the idea was that option arrays are not good enough actually.
-- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

Lester Caine

12 years ago
Stas Malyshev wrote:
> Option lists are everywhere, if you look at any framework everybody does > it. Of course, now they do it with option arrays, and if we accept that > option arrays are good then we don't need varargs either. But I thought > the idea was that option arrays are not good enough actually.
Parameter hashes are what we have been converting everything TO because it was supposed to be the 'proper way to do it' a few years back. So when did they get kicked out again? Certainly passing a hash through a verify function before acting on it makes sense with all the code I'm using now ... the verify function fills in any default values and checks the rest of the past variables, and secondary objects create detail records. I'd hate to be doing this nowadays with lists of parameters. It just would not work.
-- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

Robert Williams

12 years ago
On Sep 2, 2013, at 15:54, "Lester Caine" <lester@lsces.co.uk> wrote:
> Parameter hashes are what we have been converting everything TO because it was > supposed to be the 'proper way to do it' a few years back.
If you have lots of parameters to pass in, the better solution is to use an object, which lets you formally define what is required to be passed in. The parameter hash, or the parameter block as it was known in decades past, is a compromise solution that was widely used before OOP really caught on. In this context, it is essentially the same thing as a simple object but without the formal definition. The lack of formal definition is what makes it a terrible idea because it obfuscates the parameters of the function. If you hand off the code to someone else to use, they must to look at the implementation to see how it works to figure out what to pass in. Oh, there may be separate docs, but they can't be auto-generated, and we all know how well code docs are kept up-to-date when they're not auto-generated. Plus, PHPDoc doesn't support parameter blocks, which means that IDEs can't offer the same level of assistance with code-completion that they offer for both objects and straight parameters -- another huge downside. Parameters were invented as an abstraction around passing raw, untyped and unnamed stacks of data. Parameter blocks take us back to that. Back to the topic, I like what Stas has proposed. Further, I don't see named parameters as replacing the utility of default parameters. For long parameter lists, named parameters would usually make more sense to use, I think, but for medium lists, I think the default keyword is much cleaner because it doesn't require doubling or tripling the length of what you type for the parameter list to ensure you're getting the default value for a parameter. And where named parameters are overkill, it keeps the focus of anyone reading the code firmly on the values, not the parameter names. In other words, the two features complement each other, with one or the other being better in different contexts. I don't get a vote, but if I did, I'd say implement what Stas has put forth, and if named parameters can come into the picture at some point, implement that, too.
-- Bob Williams Notice: This communication, including attachments, may contain information that is confidential. It constitutes non-public information intended to be conveyed only to the designated recipient(s). If the reader or recipient of this communication is not the intended recipient, an employee or agent of the intended recipient who is responsible for delivering it to the intended recipient, or if you believe that you have received this communication in error, please notify the sender immediately by return e-mail and promptly delete this e-mail, including attachments without reading or saving them in any manner. The unauthorized use, dissemination, distribution, or reproduction of this e-mail, including attachments, is prohibited and may be unlawful. If you have received this email in error, please notify us immediately by e-mail or telephone and delete the e-mail and the attachments (if any).

Lester Caine

12 years ago
Robert Williams wrote:
> PHPDoc doesn't support parameter blocks, which means that IDEs can't offer the same level of assistance with code-completion that they offer for both objects and straight parameters -- another huge downside.
PHPDoc's does 'not' not support parameter blocks ... you just document them properly in the first place. Switching these to formalised objects introduces another level of complexity that detracts from their use rather than enhancing it, but again that is more to do with maintaining BC. Something that has become a second class citizen nowadays? Much of the work I've been wasting time on over the past years is re-factoring legacy code to make it E_STRICT compliant. Switching TO using arrays has been part of that exercise and was helpful in getting around the warnings raised to the original code. Much of the material I'm working with is arrays of data into and out of a database, so not naturally an 'object'? OK adding 'default' or going on to finally force named parameters on us is not going to break anything but it's creating yet more new styles of coding when what we NEED is to simplify and get back to a style of working that we can agree on and start producing applications rather than reinventing the engine every year :( Currently - as I've said many times - there is no 'style guide' to provide a best practice we can work to. PSR is probably the closest we have but even that is a clique of users with a particular agenda which is why it's not formally accepted by the general development team? Redoing everything again to conform with that would be another year or so's work for me :( Coding used to be fun - now it's just a chore :(
-- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

Marc Bennewitz

11 years ago
Hi Stas, I really like this RFC. It makes it simple to use defined defaults without the need to know about them of to updated. But I think adding "default" as new keyword is a big BC break! I personally also don't like it and asked myself why can't the parameter simply skipped? function foo ($a='a', $b='b') {} foo(); foo($a); foo(, $b); foo($a,); foo(,); Is it possible to use the default parameter on inheritance? class Bar { function foo($a='a', $b='b') {} } class Baz extends Bar { function foo($a=default, $b=default) { // do something parent::foo($a, $b); } } Marc Am 02.09.2013 um 09:17 schrieb Stas Malyshev:

Adam Harvey

11 years ago
On 14 January 2015 at 11:15, Marc Bennewitz <dev@mabe.berlin> wrote:
> But I think adding "default" as new keyword is a big BC break!
Default already is a keyword: http://php.net/switch. There's no BC break.
> I personally also don't like it and asked myself why can't the parameter > simply skipped?
That was in the original proposal, but counting commas is pretty lousy if you're skipping more than one or two parameters. Having a keyword makes it more readable. Adam

Marc Bennewitz

11 years ago
Am 14.01.2015 um 20:21 schrieb Adam Harvey:
> On 14 January 2015 at 11:15, Marc Bennewitz <dev@mabe.berlin> wrote: >> But I think adding "default" as new keyword is a big BC break! > Default already is a keyword: http://php.net/switch. There's no BC break.
OMG you are right - my fault

Guilherme Blanco

11 years ago
Hi, -1 on this proposal +1 on named parameters As of for this...
> > handy and easier. I could dig the archives but I don't remember what > > was the reason why we rejected the idea back then. > > Bikeshedding about the syntax mostly, but that all pales compared to > amount of work that needs to be done in the engine to support named > params. Unless, of course, I'm completely wrong and there's an easy way > to do it, which I am totally missing - in which case please point it out.
Pierrick and I both implemented this support for Annotations back in 2010. Maybe it's worth to look into that patch for some ideas. Regards, On Wed, Jan 14, 2015 at 2:50 PM, Marc Bennewitz <dev@mabe.berlin> wrote:
> > Am 14.01.2015 um 20:21 schrieb Adam Harvey: > >> On 14 January 2015 at 11:15, Marc Bennewitz <dev@mabe.berlin> wrote: >> >>> But I think adding "default" as new keyword is a big BC break! >>> >> Default already is a keyword: http://php.net/switch. There's no BC break. >> > > OMG you are right - my fault > > > >> I personally also don't like it and asked myself why can't the parameter >>> simply skipped? >>> >> That was in the original proposal, but counting commas is pretty lousy >> if you're skipping more than one or two parameters. Having a keyword >> makes it more readable. >> >> Adam >> >> > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
-- Guilherme Blanco MSN: guilhermeblanco@hotmail.com GTalk: guilhermeblanco Toronto - ON/Canada

Stas Malyshev

11 years ago
Hi!
> -1 on this proposal > > +1 on named parameters
Come on, we've already talked about it like 20 times and it has special paragraph in the RFC dedicated exactly to this. It's not instead named params, we can do both.
> Pierrick and I both implemented this support for Annotations back in 2010. > Maybe it's worth to look into that patch for some ideas.
Annotations are great and I'd like them to be resurrected (provided that we don't get bogged down again with "let's implement a Turing-complete DSL for for ORMs inside annotations because we have like 1 or even 2 use cases for it!") but how it is relevant to the topic or to named params? That said, if you want to branch the topic and discuss it it's fine, just please change the subj.
-- Stas Malyshev smalyshev@gmail.com

Guilherme Blanco

11 years ago
Hi Stas, As I said, we should look at that patch as we implemented Named Parameters there with everything you mentioned. Cheers, On Wed, Jan 14, 2015 at 3:23 PM, Stanislav Malyshev <smalyshev@gmail.com> wrote:
> Hi! > > > -1 on this proposal > > > > +1 on named parameters > > Come on, we've already talked about it like 20 times and it has special > paragraph in the RFC dedicated exactly to this. It's not instead named > params, we can do both. > > > Pierrick and I both implemented this support for Annotations back in > 2010. > > Maybe it's worth to look into that patch for some ideas. > > Annotations are great and I'd like them to be resurrected (provided that > we don't get bogged down again with "let's implement a Turing-complete > DSL for for ORMs inside annotations because we have like 1 or even 2 use > cases for it!") but how it is relevant to the topic or to named params? > That said, if you want to branch the topic and discuss it it's fine, > just please change the subj. > -- > Stas Malyshev > smalyshev@gmail.com >
-- Guilherme Blanco MSN: guilhermeblanco@hotmail.com GTalk: guilhermeblanco Toronto - ON/Canada

Marcio Almada

11 years ago
Marc Bennewitz, Stas,
> But I think adding "default" as new keyword is a big BC break! > I personally also don't like it and asked myself why can't the parameter
simply skipped? Default is already a reserved word AFAIK. But I've been thinking about alternatives to parameter skipping syntax which brought me the Golang blank identifier _ to mind: create_query("deleted=0", "name", _, _, true); Still not sure if it's better than `default`, though. 2015-01-14 16:15 GMT-03:00 Marc Bennewitz <dev@mabe.berlin>:

Simon J Welsh

11 years ago
> On 15/01/2015, at 06:33, Marcio Almada <marcio.web2@gmail.com> wrote: > > Marc Bennewitz, Stas, > >> But I think adding "default" as new keyword is a big BC break! >> I personally also don't like it and asked myself why can't the parameter > simply skipped? > > Default is already a reserved word AFAIK. But I've been thinking about > alternatives to parameter skipping syntax which brought me the Golang > blank identifier _ to mind: > > create_query("deleted=0", "name", _, _, true); > > Still not sure if it's better than `default`, though.
That would be a BC break as you can currently have a constant _. An existing keyword makes upgrading easier, and default is easier to understand by someone who doesn’t know about the feature than an underscore. --- Simon Welsh Admin of http://91carriage.com/ – Specialised SilverStripe hosting

Patrick Schaaf

11 years ago
Am 14.01.2015 20:50 schrieb "Simon J Welsh" <simon@welsh.co.nz>:
> > > create_query("deleted=0", "name", _, _, true); > > > > Still not sure if it's better than `default`, though. > > That would be a BC break as you can currently have a constant _.
A visually pleasing (IMO), even easier to type, and non-BC alternative, could be using a dash: create_query("deleted=0", "name", -, -, true); best regards Patrick

Yasuo Ohgaki

11 years ago
Hi all, On Fri, Jan 16, 2015 at 7:29 PM, Patrick Schaaf <php@bof.de> wrote:
> Am 14.01.2015 20:50 schrieb "Simon J Welsh" <simon@welsh.co.nz>: > > > > > create_query("deleted=0", "name", _, _, true); > > > > > > Still not sure if it's better than `default`, though. > > > > That would be a BC break as you can currently have a constant _. > > A visually pleasing (IMO), even easier to type, and non-BC alternative, > could be using a dash: > > create_query("deleted=0", "name", -, -, true); >
Cryptic notation is not a PHP way. IMHO. I like original "default" proposal and it is good enough. Regards,
-- Yasuo Ohgaki yohgaki@ohgaki.net

Marcio Almada

11 years ago
> Cryptic notation is not a PHP way. IMHO.I like original "default" proposal and it is good enough. > Regards,
When I suggested `_` it was more as a feature wandering. I like `default` too. The RFC looks good enough as it is now :) 2015-01-17 22:14 GMT-03:00 Yasuo Ohgaki <yohgaki@ohgaki.net>:

Marcio Almada

11 years ago
Just a note: I still think a single char token (like `~`) would look great and wouldn't be "cryptic" like Yasuo argued. But, as said before, it's just a minor observation. The `default` token is a great option and sounds very intuitive to anyone I've asked for opinions. 2015-01-17 22:52 GMT-03:00 Marcio Almada <marcio.web2@gmail.com>:

Andrew Faulds

11 years ago
Hi Marcio,
> On 18 Jan 2015, at 02:01, Marcio Almada <marcio.web2@gmail.com> wrote: > > Just a note: > > I still think a single char token (like `~`) would look great and > wouldn't be "cryptic" like Yasuo argued. But, as said before, it's > just a minor observation. The `default` token is a great option and > sounds very intuitive to anyone I've asked for opinions.
For consistency with list(), we could also just put nothing: foo($bar, , $baz); Which is like: list($bar, , $baz) = $arr; Thoughts?
-- Andrea Faulds http://ajf.me/

Marcio Almada

11 years ago
Andrea,
> For consistency with list(), we could also just put nothing: > > foo($bar, , $baz); > > Which is like: > > list($bar, , $baz) = $arr; > > Thoughts?
Not sure. Do we consider both contexts (list assignment skipping and parameter skipping) as assignments? If so, then the consistency arguments seems very strong to me. Only point against the consistency path is that in the context of list() the blank identifier is used to discard a value, while on parameter skipping the blank identifier inherits a previously declared value.

Adam Harvey

11 years ago
On 17 January 2015 at 18:04, Andrea Faulds <ajf@ajf.me> wrote:
> For consistency with list(), we could also just put nothing: > > > foo($bar, , $baz); > > Which is like: > > list($bar, , $baz) = $arr; > > Thoughts?
That was Stas's original, original proposal way back when. I argued then for having "default" as a placeholder, and still would today — in the case where a function with, say, ten optional parameters[0] is being called and eight of them should be the default, I think it's a bit rough for somebody inheriting that code to have to count commas. Having a token increases readability, IMO, and costs us nothing except a few keystrokes, which isn't going to break the camel's back in a language that requires "function" each time you declare a function. Adam [0] Yes, that's probably poor API design. You and I both know someone will do it, though. :)

Rasmus Lerdorf

11 years ago
On Jan 17, 2015, at 17:52, Marcio Almada <marcio.web2@gmail.com> wrote:
>> Cryptic notation is not a PHP way. IMHO.I like original "default" proposal and it is good enough. >> Regards, > > When I suggested `_` it was more as a feature wandering. I like > `default` too. The RFC looks good enough as it is now :)
_ is not really an option since it is the standard gettext() shortcut. Eg. http://en.m.wikipedia.org/wiki/Gettext#Programming http://php.net/_ -Rasmus

Marcio Almada

11 years ago
Rasmus,
> _ is not really an option since it is the standard gettext() shortcut.
Yup, Simon J. pointed that out too so usage of `_` was already a discarded topic. The top topic now is a possible consistency with the syntax already allowed when using list. Ex: list($bar, , $baz) = ['good', 'trash', 'nice']; Andrea,
> …that probably made no sense. But I think there’s a case to be made that
since list() follows this syntax, we should for function calls to. But I get it, it would also prevent language syntax from growing just to have a trivial feature. Apart from the debate about meaning of the assignment using a blank identifier, it would be beneficial to use the same syntax even though situations are distinct. I guess only Stas can decide to give up on `default` and use a blank identifier. Anyway, hope this decision don't affect the voting negatively, feature is cool. 2015-01-18 0:32 GMT-03:00 Rasmus Lerdorf <rasmus@lerdorf.com>:

Stas Malyshev

11 years ago
Hi!
> Is it possible to use the default parameter on inheritance? > > class Bar { > function foo($a='a', $b='b') {} > } > > class Baz extends Bar { > function foo($a=default, $b=default) { > // do something > parent::foo($a, $b); > } > }
It's not part of the original proposal, and I'm not sure how easy it would be to implement, but it sounds like a nice extension, I didn't think about it. Since the RFC is already in vote, I won't change it now, but I'll look into if it's possible to do it, and if the RFC is accepted, and it proves possible, I'll propose it separately.
-- Stas Malyshev smalyshev@gmail.com

Stas Malyshev

11 years ago
Hi!
> It's not part of the original proposal, and I'm not sure how easy it > would be to implement, but it sounds like a nice extension, I didn't > think about it. Since the RFC is already in vote, I won't change it now,
Strike that, I was confused, for some reason I thought I've already put it to vote, even though I've put to vote my other RFC (shameless plug: https://wiki.php.net/rfc/default_ctor, go there and vote Yes ;). Too many RFCs :) So I'll think if it's easy to add and maybe add it before it goes to vote.
-- Stas Malyshev smalyshev@gmail.com

Robert Stoll

11 years ago
Hi Stas,
> -----Ursprüngliche Nachricht----- > Von: Stanislav Malyshev [mailto:smalyshev@gmail.com] > Gesendet: Mittwoch, 14. Januar 2015 21:26 > An: Marc Bennewitz; internals@lists.php.net > Betreff: Re: [PHP-DEV] [RFC] Skipping parameters take 2 > > Hi! > > > Is it possible to use the default parameter on inheritance? > > > > class Bar { > > function foo($a='a', $b='b') {} > > } > > > > class Baz extends Bar { > > function foo($a=default, $b=default) { > > // do something > > parent::foo($a, $b); > > } > > } > > It's not part of the original proposal, and I'm not sure how easy it would be to implement, but it sounds like a nice > extension, I didn't think about it. Since the RFC is already in vote, I won't change it now, but I'll look into if
it's possible to do
> it, and if the RFC is accepted, and it proves possible, I'll propose it separately. > > -- > Stas Malyshev > smalyshev@gmail.com
This would be quite a nice feature, even if this RFC does not pass. Just as hint, there are ambiguous case which need to be considered: interface A{ function foo($a=1); } interface B{ function foo($a="hi"); } class C implements A, B{ function foo($a=default){} //what would be the default value? } Cheers, Robert

Marc Bennewitz

11 years ago
Hi Robert Am 16.01.2015 um 11:04 schrieb Robert Stoll:
> Hi Stas, > >> -----Ursprüngliche Nachricht----- >> Von: Stanislav Malyshev [mailto:smalyshev@gmail.com] >> Gesendet: Mittwoch, 14. Januar 2015 21:26 >> An: Marc Bennewitz; internals@lists.php.net >> Betreff: Re: [PHP-DEV] [RFC] Skipping parameters take 2 >> >> Hi! >> >>> Is it possible to use the default parameter on inheritance? >>> >>> class Bar { >>> function foo($a='a', $b='b') {} >>> } >>> >>> class Baz extends Bar { >>> function foo($a=default, $b=default) { >>> // do something >>> parent::foo($a, $b); >>> } >>> } >> It's not part of the original proposal, and I'm not sure how easy it would be to implement, but it sounds like a nice >> extension, I didn't think about it. Since the RFC is already in vote, I won't change it now, but I'll look into if > it's possible to do >> it, and if the RFC is accepted, and it proves possible, I'll propose it separately. >> >> -- >> Stas Malyshev >> smalyshev@gmail.com > This would be quite a nice feature, even if this RFC does not pass. Just as hint, there are ambiguous case which need to > be considered: > > interface A{ > function foo($a=1); > } > interface B{ > function foo($a="hi"); > } > class C implements A, B{ > function foo($a=default){} //what would be the default value? > } > > Cheers, > Robert
The default value have be the one of the parent. if there is no parent you have the following options: * Syntax error (I prefer) * If defined use from interface * If ambiguous: * Syntax error * Choose one (bad in my opinion) Marc

Stas Malyshev

11 years ago
Hi!
> This would be quite a nice feature, even if this RFC does not pass. > Just as hint, there are ambiguous case which need to be considered: > > interface A{ function foo($a=1); } interface B{ function > foo($a="hi"); } class C implements A, B{ function foo($a=default){} > //what would be the default value? }
I'm not sure specifying the default on the interface makes much sense, since you'd have to override it anyway. I am inclined to only support it for extending (parent class). But if there's an easy way to do it for interfaces, it's ok - but checking that there are no duplicates may be expensive.
-- Stas Malyshev smalyshev@gmail.com

Robert Stoll

11 years ago
> -----Ursprüngliche Nachricht----- > Von: Stanislav Malyshev [mailto:smalyshev@gmail.com] > Gesendet: Freitag, 16. Januar 2015 21:35 > An: Robert Stoll; 'Marc Bennewitz'; internals@lists.php.net > Betreff: Re: AW: [PHP-DEV] [RFC] Skipping parameters take 2 > > Hi! > > > This would be quite a nice feature, even if this RFC does not pass. > > Just as hint, there are ambiguous case which need to be considered: > > > > interface A{ function foo($a=1); } interface B{ function foo($a="hi"); > > } class C implements A, B{ function foo($a=default){} //what would be > > the default value? } > > I'm not sure specifying the default on the interface makes much sense, since you'd have to override it anyway. I am > inclined to only support it for extending (parent class). But if there's an easy way to do it for interfaces, it's ok
- but checking
> that there are no duplicates may be expensive. > > -- > Stas Malyshev > smalyshev@gmail.com > > -- > PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
I think you are right and restricting it to the parent class only would remove the ambiguity

Stas Malyshev

11 years ago
Hi!
> class Baz extends Bar { > function foo($a=default, $b=default) { > // do something > parent::foo($a, $b); > } > }
I tried to implement this, however there's a major issue that I do not know how to overcome. The issue is that when we compile method foo() we do not know the default values. These values are stored in RECV_INIT opcodes directly, so when we find out what the actual values are - i.e. when we resolve inheritance for class Baz - it may be in runtime, so we'd have to update opcodes for RECV_INIT in foo() in runtime. Which is not going to sit well with opcode cache, which assumes opcodes do not change. I'm not sure yet how to solve this - since the values are only stored in the opcodes it is not easy to locate them in runtime, so even if we make 'default' zvals some special type we'd still have a problem finding the right value since the binding happens in runtime and we don't have now any place to store the result of that binding. I'll think a bit more about it, in the meantime any ideas about how to resolve this problem are welcome.
-- Stas Malyshev smalyshev@gmail.com