On 6/25/13 10:57 AM, Anthony Ferrara wrote:
>
>> Hey all,
>>
>> I want to throw out this draft RFC to get the concept floating around and
>> get feedback early.
>>
>> https://wiki.php.net/rfc/**protocol_type_hinting<https://wiki.php.net/rfc/protocol_type_hinting>
>>
>> There are still open questions, and a more complete (and cleaner)
>> implementation will be needed before officially proposing it, but I wanted
>> to get the concept out as soon as possible.
>>
>> What do you think?
>>
>> Thanks!
>>
>> Anthony
>>
>
I did like the concept, however I'd like to double-check if I didn't missed
anything.
I don't see the main reason, to create a "protocol" syntax if you're only
verify that a specific class implements a specific method.
For instance:
interface IStoreableObject {
function save($key, $value);
function fetch($key);
function exists($key);
function count();
}
interface IQueryable {
function where($expression);
function orderBy($expression);
function limit($min, $max);
}
I can create a class that implements these two interfaces, such as
class DbObject implements IStorableObject, IQueryable { }
and then in my function test if these interfaces was implemented by using
instanceof.
This was a quick setup for my question:
If you allow in the protocol to specify only ONE class/interface, I don't
see any reason to use it. Today we can use type-hinting and the instanceof
operator.
However, If you allows using the protocol syntax to test against multiple
interfaces, for instance
function fetchSomeData($identifier, <IStorableObject, IQueryable> $object) {
}
It will be a great addition. So can you clarify yourself?