RE: [PHP-DEV] RFC: Protocol Type Hinting
| From: | jbondc@openmv.com | Date: | Thu, 27 Jun 2013 14:47:41 +0000 |
| Subject: | RE: [PHP-DEV] RFC: Protocol Type Hinting | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-67956@lists.php.net to get a copy of this message | ||
>I agree the use-cases are slightly weak. This is a draft RFC. It's supposed to help
>identify
> the areas where we can improve it. Help identify use-cases. Help dig it out.
I think Ralph has the right idea:
register_compatible_types($yourType, $myType);
A better name might be (only for interfaces):
register_instanceof($compatibleInterface, $interface);
e.g.
class ThirdParty {
static foo(LoggerInterface $log) {}
}
class Bar implements My_Logging_Inferface {}
echo (Bar instanceof LoggerInterface); // false
register_instanceof('My_Logging_Inferface', 'LoggerInterface');
echo (Bar instanceof LoggerInterface); // true
ThirdParty::foo(new Bar); // no error since 'My_Logging_Interface' is compatible with
LoggerInterface
In summary, it would allow for user-land registration of compatible interfaces to third party
libraries.
There's definitely a couple of use cases where I would have liked to use something to this.
Advantages to wrapping the feature in a function:
- No extra syntax to support in core
- No 'new concept' for developers to learn
- It can be disabled (which OO purists might like)
disable_functions = register_instanceof