Re: Using default argument values in the middle of the argument list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 02 Jun 2012 21:35:28 +0200, Matijn Woudt <tijnema@xxxxxxxxx> wrote:

It does not state it works only at the end of the list, it states that
it only makes sense to use it at the end of the argument list to be
able to call the function with less arguments. In case you want to use
it as suggested in [2], you can use it anywhere. You can rely on that
in any PHP version from 5 upwards, just because version 4 doesn't
support type hinting at all.

- Matijn

[2] http://php.net/manual/en/language.oop5.typehinting.php

Wow that's great. Just to be sure are we talking about functions it's default arguments precedes its non-default arguments:

function f ( Classname $a = null, Classname $b ) { ... }

I believe it should be clearly stated in documentation that it is possible for several reasons.

- I have never thought of using type hints and default arguments this way until I found it by accident. - I have never seen someone else using it (I've just search installed PEAR packages, codebase of Symphony2, Zend2 and several others and found *one* function definition taking advantage of this*). - As far as i know other languages that support default argument values allow specifying default arguments only for rightmost function arguments. - As far as i know the only part of documentation that illustrates function declarations having default argument preceding non-default arguments is the one titled: "Incorrect usage of default function arguments" in http://www.php.net/manual/en/functions.arguments.php.

I just wanted to be sure this is haw it is supposed to be used.

* DibiColumnInfo::__construct(IDibiReflector $reflector = NULL, array $info) in https://github.com/dg/dibi/blob/master/dibi/libs/DibiDatabaseInfo.php#L458

-- Oliver

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux