Hi,

On Thu, May 27, 2010 at 00:30, Derick Rethans <der...@php.net> wrote:
> On Wed, 26 May 2010, Davey Shafik wrote:
>
>> Would it be possible to support two syntaxes:
>>
>> function foo( (int) $bar) { }  // auto-cast to int
>> function foo(int $bar) { }      // require int
>
> I think that's a brilliant plan. We won't ever agree on whether we want
> either strict type hinting, or casting typehinting and this provides
> both possibilities with the following pros:
>
> - The syntax is consistent for casting. We already support (int) $bar
>  anywhere else.
> - The syntax is consistent for strict type checking. We already support
>  throwing errors with foo(ClassName $bar).
> - There are no new conversion rules that can confuse people.
> - Type checking with "int $bar" will stay fast, as we only have to
>  compare type.

+1

- The current type hint is strict, let's not add cases to it that
isn't, as it would be inconsistent (and not the opposite...)
- Strict typing helps detecting programming errors, if I expect a
function to be called with integers arguments only, I'd rather be
alerted if it gets called with a non-int, than having it silenced and
magically auto-casted. Personally, I don't have random values with
random types floating around in my applications...

All that to say that I'd like the normal type hint to be strict, if
another language feature does auto casting, I don't care.

Best,

>
>> There has never been casting to objects other than stdClass, so I
>> don't think it conflicts that there is no:
>>
>> function foo( (DBAdapter) $bar) { }
>
> Something we could add later? :)

IMO it doesn't make sense to down cast or up cast objects in PHP,
since all type checks happen at runtime.

>
> regards,
> Derick
>
> --
> http://derickrethans.nl | http://xdebug.org
> Like Xdebug? Consider a donation: http://xdebug.org/donate.php
> twitter: @derickr and @xdebug
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
Etienne Kneuss
http://www.colder.ch

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to