====== PHP RFC: Resource typehint ======
* Version: 0.1
* Date: 2015-11-11
* Author: Ben Scholzen, mail@dasprids.de
* Status: Under Discussion
* First Published at: https://wiki.php.net/rfc/resource_typehint
===== Introduction =====
So far, every PHP type is supported by both parameter typehints and return types, except resources. This RFC should close this gap.
===== Proposal =====
The ``resource`` typehint and return type should be added to the engine, working the same way like ``is_resource()`` does. This would also mean to make ``resource`` a reserved classname.
function should_return_resource(): resource {
return true; // Return value of should_return_resource() must be of the type resource, boolean returned
}
function only_accepts_resource(resource $foo) {
}
only_accepts_resource(fopen('php://memory', 'w'));
===== Backward Incompatible Changes =====
This RFC adds ``resource`` as reserved classname. This may collide with existing classes which are neither namespaced nor prefixed.
===== Proposed PHP Version(s) =====
This is proposed for the next minor version of PHP, currently PHP 7.1.
===== Proposed Voting Choices =====
As this is a language change, a 2/3 majority is required. The vote is a straight Yes/No vote for accepting the RFC and merging the patch.
===== Patches and Tests =====
Considered final patch:
https://github.com/php/php-src/pull/1631