2012/10/16 Rasmus Lerdorf <ras...@lerdorf.com>

> The rule in PHP for any sort of type hinting is that it is only done for
> non-coercable types. In cases where there is simply no way to recover
> from passing the wrong type, it is good to catch it as early as
> possible. Extending this to also cover scalar coercable types would be
> disastrous for the entire ecosystem and would completely change PHP.


My point was not about scalar types. It was about porting the logic of
parameters type hinting to object properties. Nothing more, nothing less.


And the fact that it is "optional" means absolutely nothing because once
> some piece of your system has "optionally" decided to use it you don't
> have the option not to abide by it, and it certainly isn't a hint, it is
> a strong type. You will end up casting every call to everything all the
> time just to be safe.
>

I use parameters type hinting everyday. I can say it's very useful. And I
never needed to cast anything.
If the object model is used wisely, and if type hinting is used as an
option (i.e. don't use it when you know you'll need "mixed" data), it's a
very good thing.

I don't see why it couldn't be as good for properties as it is for
parameters. But Stas said it was already discussed a lot here, so I give
up.  :-)

Reply via email to