rfc:resource_typehint

PHP 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

rfc/resource_typehint.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1