Prompted by a discussion in the Slack channel, we need some guidelines and ground rules for the conversion of components to type-hinted PHP 7.1 behaviour. The main point to make is that adding type hints is not going to be a simple case of just, well, adding the type hints. Refactoring is going to have to be done where methods are taking multiple types and these refactorings may be tricky. We need to make a decision on how and when to deprecate methods that take multiple typed arguments in order to clean up the API.
This is a unique opportunity to tidy up the API massively but we don’t want to break everything for everyone. For me we should strive to as close to 100% type hinted as possible and refactor out places where we can’t achieve that because of backwards compatibility, marking the mixed type method as deprecated.
The example used in the Slack chat was Zend\Forms’s
add() method (you can find it here). Presently it takes an array/traversable or element interface. This should be split into 3 methods
addElement (naming up for debate this is an example only) each having strictly typed parameters. The original
add method would then have a mixed type and be marked deprecated and infer which call to proxy to depending on the type.
We should also remove
@param docblocks where strict typing can happen in my opinion, but this is up for debate because of the usefulness of the comment about what the param does.
Anyway, this has rambled on enough, these are just my opinions and I’m dumping them here to open the discussion and hopefully get a set of guidelines in place so people can go along and convert components.