rfc:callable
                This is an old revision of the document!
Request for Comments: callable type hint
- Version: 1.0
 - Date: 2011-06-07
 - Author: Hannes Magnusson bjori@php.net
 - Status: Under Discussion
 - First Published at: http://wiki.php.net/rfc/callable
 
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' is a data structure not unlike 'balanced binary tree' and 'readable file', and none of them make sense have as a part of the language syntax. They belong in userspace.
 - A “strict typing error” is hard to handle in user-space gracefully.
 
 - Everyone else seem to like the idea, so far.
 - As for the patch itself, Felipe pointed out that the patch is missing an method in ext/reflection to retrieve the typehint information.
 - Things to finalize:
- Type name: documentation uses 'callback', not 'callable' as proposed
 - Are initializers allowed?
 - Does validation include visibility, as is_callable() does?
 - Reflection support
 - Arginfo support
 
 
Changelog
- June 7th 2011, Initial writeup
 
rfc/callable.1308183073.txt.gz · Last modified:  (external edit)