# [RFC] Skipping parameters take 2

- Thread: https://staging.externals.io/message/68826
- Original archive: https://news-web.php.net/php.internals/68826
- Started by Stas Malyshev on 2013-09-02T07:17:58+00:00
- Messages: 68
- RFC: Skipping optional parameters (Declined) — https://staging.externals.io/rfc/skipparams.md
- Page 1 of 3: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://staging.externals.io/message/68826.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://staging.externals.io/search.md?q={query} · RFCs at https://staging.externals.io/rfc.md · JSON API at https://staging.externals.io/api · documentation at https://staging.externals.io/llms.txt

---

## #68826 — Stas Malyshev — 2013-09-02T07:17:58+00:00

URL: https://staging.externals.io/message/68826#68826

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

---

## #68827 — Laruence — 2013-09-02T07:31:04+00:00

URL: https://staging.externals.io/message/68826#68827 · In reply to: #68826

> 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
>
> --
> 
> 
>



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

---

## #68829 — Stas Malyshev — 2013-09-02T07:41:13+00:00

URL: https://staging.externals.io/message/68826#68829 · In reply to: #68827

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

---

## #68832 — Florin Patan — 2013-09-02T08:01:44+00:00

URL: https://staging.externals.io/message/68826#68832 · In reply to: #68829

> Hi!
>
> > […]
>
> 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
>
> --
> 
> 
>


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

---

## #68833 — Ferenc Kovacs — 2013-09-02T08:07:12+00:00

URL: https://staging.externals.io/message/68826#68833 · In reply to: #68829

On Mon, Sep 2, 2013 at 9:41 AM, Stas Malyshev <smalyshev@sugarcrm.com>wrote:

> Hi!
>
> > […]
>
> 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

---

## #68835 — Lester Caine — 2013-09-02T09:02:52+00:00

URL: https://staging.externals.io/message/68826#68835 · In reply to: #68833

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

---

## #68836 — Jannik Zschiesche — 2013-09-02T09:16:54+00:00

URL: https://staging.externals.io/message/68826#68836 · In reply to: #68835

Am Montag, 2. September 2013 um 11:02 schrieb Lester Caine:

> Ferenc Kovacs wrote:
> > […]
> 
> 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

---

## #68837 — Nikita Popov — 2013-09-02T09:20:27+00:00

URL: https://staging.externals.io/message/68826#68837 · In reply to: #68826

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

---

## #68839 — Lester Caine — 2013-09-02T10:24:11+00:00

URL: https://staging.externals.io/message/68826#68839 · In reply to: #68836

Jannik Zschiesche wrote:
> > […]
>
> 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

---

## #68840 — Ferenc Kovacs — 2013-09-02T10:26:25+00:00

URL: https://staging.externals.io/message/68826#68840 · In reply to: #68839

> Jannik Zschiesche wrote:
>
> > […]
>
> ? ... 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

---

## #68841 — Lester Caine — 2013-09-02T10:43:00+00:00

URL: https://staging.externals.io/message/68826#68841 · In reply to: #68840

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

---

## #68842 — Derick Rethans — 2013-09-02T10:48:01+00:00

URL: https://staging.externals.io/message/68826#68842 · In reply to: #68826

> 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

---

## #68843 — Sebastian Krebs — 2013-09-02T10:53:20+00:00

URL: https://staging.externals.io/message/68826#68843 · In reply to: #68841

2013/9/2 Lester Caine <lester@lsces.co.uk>

> Ferenc Kovacs wrote:
>
> > […]
>
> 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>
>
> --
> 
> 
>
>


-- 
github.com/KingCrunch

---

## #68844 — johannes@schlueters.de — 2013-09-02T11:03:37+00:00

URL: https://staging.externals.io/message/68826#68844 · In reply to: #68842

On Mon, 2013-09-02 at 11:48 +0100, Derick Rethans wrote: 
> > […]
> 
> 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

---

## #68846 — Etienne Kneuss — 2013-09-02T11:28:57+00:00

URL: https://staging.externals.io/message/68826#68846 · In reply to: #68842

> 
>
> > […]
> /*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
>
> --
> 
> 
>
>


-- 
Etienne Kneuss

---

## #68847 — Pierre Joye — 2013-09-02T12:32:16+00:00

URL: https://staging.externals.io/message/68826#68847 · In reply to: #68826

hi Stas,


> 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

---

## #68849 — Sebastian Krebs — 2013-09-02T12:52:42+00:00

URL: https://staging.externals.io/message/68826#68849 · In reply to: #68847

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:
> > […]
>
> 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
>
> --
> 
> 
>
>


-- 
github.com/KingCrunch

---

## #68853 — jbondc@openmv.com — 2013-09-02T16:04:11+00:00

URL: https://staging.externals.io/message/68826#68853 · In reply to: #68849

> 2013/9/2 Pierre Joye <pierre.php@gmail.com>
> 
> > […]
> 
> 
> 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.

---

## #68855 — Lazare Inepologlou — 2013-09-02T17:23:48+00:00

URL: https://staging.externals.io/message/68826#68855 · In reply to: #68853

2013/9/2 jbondc@openmv.com <jbondc@openmv.com>

> 
> > […]
>
> 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

---

## #68856 — jbondc@openmv.com — 2013-09-02T18:56:09+00:00

URL: https://staging.externals.io/message/68826#68856 · In reply to: #68855

> 
> > […]
> 
> 
> 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

---

## #68858 — Stas Malyshev — 2013-09-02T20:06:50+00:00

URL: https://staging.externals.io/message/68826#68858 · In reply to: #68833

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

---

## #68859 — Stas Malyshev — 2013-09-02T20:11:39+00:00

URL: https://staging.externals.io/message/68826#68859 · In reply to: #68837

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

---

## #68861 — Stas Malyshev — 2013-09-02T20:12:51+00:00

URL: https://staging.externals.io/message/68826#68861 · In reply to: #68842

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

---

## #68862 — Stas Malyshev — 2013-09-02T20:19:56+00:00

URL: https://staging.externals.io/message/68826#68862 · In reply to: #68847

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

---

## #68864 — Levi Morrison — 2013-09-02T20:47:59+00:00

URL: https://staging.externals.io/message/68826#68864 · In reply to: #68859

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

> Hi!
>
> > […]
>
> I don't understand. Who says I should do that? I certainly don't see how
> I should.
>
> > […]
>
> 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

---

Next page: https://staging.externals.io/message/68826.md?page=2
