On Tue, Oct 16, 2012 at 10:31 AM, Amaury Bouchard <ama...@amaury.net> wrote:
> 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.
> :-)

It is foolish to think that these two bits of code are behaviorally different:

class Entity {
    DateTime $last_modified;
}
//vs
class Entity {
    public $last_modified {
        get();
        set(DateTime $last_modified);
    }
}

The latter is a more verbose way of saying the former (assuming the
get returns the same type as the set accepts).  The latter is
definitely capable of doing more than the former, such as private set
and public get. The former piece of code is simply a public get and
public set such that the type is always DateTime. It would be nice to
have the former syntax because of how succinct it is, but I am not an
experienced core programmer. I am unsure how feasible it is to
implement.

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

Reply via email to