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, Jun 2, 2012 at 8:30 PM, oliver gondža <ogondza@xxxxxxxxx> wrote:
> On Sat, 02 Jun 2012 17:13:55 +0200, Matijn Woudt <tijnema@xxxxxxxxx> wrote:
>
>>
>> Hi Oliver,
>>
>> I think the example at [1] demonstrates that it is possible, but it
>> also notes that it is pretty useless. Why are you interested in this?
>>
>> - Matijn
>>
>> [1] http://www.php.net/manual/en/functions.arguments.php#example-153
>
>
> Hi,
>
> Thanx for your response.
>
> PHP class type hints are bit more restrictive than in say Java
> since it does not accept null as a value of a class. This provides
> great guarantees, however, sometimes it is desirable to allow null as well.
>
> This can be done using:
>
> function func ( Classname $a = null )
>
> Unfortunately, according to documentation this will work only at the end of
> parameter list. So this restriction force you to put nullable arguments at
> the end of argument list or not use type hints at all. In the worst case
> scenario you have to choose between use of illogical order of arguments,
> reimplementation of type hinting for arguments that comes after the
> nullable one or use no type hinting at all for nullable arguments:

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

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