Re: [RFC - Discussion] Parameter Type Casting Hints
| From: | Anthony Ferrara | Date: | Sun, 04 Mar 2012 17:17:17 +0000 |
| Subject: | Re: [RFC - Discussion] Parameter Type Casting Hints | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-58587@lists.php.net to get a copy of this message | ||
On Mar 4, 2012 11:47 AM, "Lazare Inepologlou" <linepogl@gmail.com> wrote:
>
>
> Anthony, just a tiny detail in your RCF:
>
>> So (int) $foo = null and (int) $foo = 1 are both supported, but (int)
$foo = “1” will generate an E_COMPILE_ERROR.
>
>
> If null is going to be cast, (int)null is 0. So I don't think it should
be a valid default value.
Well, there were two reasons that I added null: first, for consistency with
the existing type hints. Second, and more importantly, to allow checking
if a parameter is specified. So without null, you couldn't tell the
difference between an explicit 0 and an implicit (not specified) 0. This
way, you can. I admit the use cases for that are rather slim, but a good
portion of internal functions behave this way (substr comes to mind)...
I think it is worth discussing further, as your point is indeed valid...
>
> Lazare INEPOLOGLOU
> Ingénieur Logiciel
>
>
> 2012/3/4 Anthony Ferrara <ircmaxell@gmail.com>
>>
>> Hey all,
>>
>> I've drafted an RFC for the Parameter type casting hint proposal that
>> I posted to before. Attached to the RFC is a patch that's proposed
>> for inclusion in core for functionality (it doesn't include news
>> entries, or documentation, or any of the other steps that would be
>> needed prior to commit).
>>
>> https://wiki.php.net/rfc/parameter_type_casting_hints
>>
>> Please provide feedback here on the implementation and RFC topics.
>>
>> Thanks,
>>
>> Anthony
>>
>> --
>> PHP Internals - PHP Runtime Development Mailing List
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
On Mar 4, 2012 11:47 AM, "Lazare Inepologlou" <linepogl@gmail.com> wrote:
>
> Anthony, just a tiny detail in your RCF:
>
> So (int) $foo = null and (int) $foo = 1 are both supported, but (int) $foo
>> = “1” will generate an E_COMPILE_ERROR.
>>
>
> If null is going to be cast, (int)null is 0. So I don't think it should be
> a valid default value.
>
>
> Lazare INEPOLOGLOU
> Ingénieur Logiciel
>
>
> 2012/3/4 Anthony Ferrara <ircmaxell@gmail.com>
>
>> Hey all,
>>
>> I've drafted an RFC for the Parameter type casting hint proposal that
>> I posted to before. Attached to the RFC is a patch that's proposed
>> for inclusion in core for functionality (it doesn't include news
>> entries, or documentation, or any of the other steps that would be
>> needed prior to commit).
>>
>> https://wiki.php.net/rfc/parameter_type_casting_hints
>>
>> Please provide feedback here on the implementation and RFC topics.
>>
>> Thanks,
>>
>> Anthony
>>
>> --
>> PHP Internals - PHP Runtime Development Mailing List
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>