rfc:callable

This is an old revision of the document!


Request for Comments: How to write RFCs

The problem

Frameworks have started to adopt Closures for callbacks, utilizing the 'Closure' typehint. That has an unfortunate sideeffect of requiring already-existing-methods to be wrapped into a closure calling that method. Additionally, the PHP documentation on closures indicates that the “Closure” class is considered an implementation detail, and may be subject to change in the future -- which means that typehinting on Closure may break in the future.

The solution

Introducing a callable typehint.

The typehint would allow a string with a function name, an array composed of classname/obj+methodname, and a closure.

Patch

Previous discussions

Discussion summary
  • The only arguments against the idea came from Stas, making the argument;
    • 'callable' are nothing different then 'balanced binary tree' and 'readable file', and none of them make sense to have typehints for.
    • A “strict typing error” is hard to handle in user-space gracefully
  • Everyone else seem to like the idea.
  • As for the patch itself, Felipe pointed out that the patch is missing an method in ext/reflection to retrieve the typehint information.

Changelog

  • June 7th 2011, Initial writeup
rfc/callable.1307462364.txt.gz · Last modified: 2017/09/22 13:28 (external edit)