rfc:protocol_type_hinting
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:protocol_type_hinting [2013/06/26 16:43] – [Standards Based Interface Declarations] ircmaxell | rfc:protocol_type_hinting [2013/09/03 12:28] – Withdrawn ircmaxell | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2013-06-25 | * Date: 2013-06-25 | ||
* Author: Anthony Ferrara < | * Author: Anthony Ferrara < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 89: | Line 89: | ||
} | } | ||
class StaticLogger { | class StaticLogger { | ||
- | public static function log($message); | + | public static function log($message) |
} | } | ||
class OtherLogger { | class OtherLogger { | ||
- | public static function log($message, | + | public static function log($message, |
} | } | ||
Bar:: | Bar:: | ||
Line 234: | Line 234: | ||
It also solves the triangular dependency problem since the sender never needs to explicitly require the dependency. That can be left for an off-line check (or a test), reducing the amount of and need for dependency resolving tools for the purpose of common interfaces... | It also solves the triangular dependency problem since the sender never needs to explicitly require the dependency. That can be left for an off-line check (or a test), reducing the amount of and need for dependency resolving tools for the purpose of common interfaces... | ||
+ | |||
+ | ==== Trait Typing ==== | ||
+ | |||
+ | Currently, traits do not allow for specifying of typing information. And this is a good thing (it is by design). | ||
+ | |||
+ | However, there are many times where we may wish to infer that the functionality presented by a trait is present in an object. An example would be Zend Framework' | ||
+ | |||
+ | <file php ProvidesEvents.php> | ||
+ | <?php | ||
+ | namespace Zend\EventManager; | ||
+ | trait ProvidesEvents { | ||
+ | protected $events; | ||
+ | public function setEventManager(EventManagerInterface $events) { /* snip */ } | ||
+ | public function getEventManager() { /* snip */ } | ||
+ | } | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | As the current system stands, classes that use the trait need to also implement a separate interface to get the message of the behavior across to the receiver that it supports events. | ||
+ | |||
+ | With Structural Type Hinting, we can instead hint against the trait directly, which would require a class with the same public API that the trait provides, // | ||
+ | |||
+ | <file php RequiresEvents.php> | ||
+ | <?php | ||
+ | function triggerEvent(< | ||
+ | $target-> | ||
+ | } | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | If the object uses the trait, it will always resolve. But it also gives other classes which implement the same public API the ability to resolve the trait. | ||
==== The Place For Current Interfaces ==== | ==== The Place For Current Interfaces ==== |
rfc/protocol_type_hinting.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1