rfc:use-static-function

This is an old revision of the document!


PHP RFC: Static "use function"

Introduction

This RFC proposes an extension to the use function statement, providing a means of aliasing public static functions from classes as file-local functions.

At present, functions cannot be autoloaded - as a consequence, developers have been forced to either preload all functions (not knowing if they get called or not) - or put them in (abstract) classes as public static functions (the more popular approach in Composer packages) and qualify every call with a class-name (or alias.)

While function autoloading has been proposed to address this issue, this RFC has been stalled several times due to problems with name-resolution, to which no good solution has been proposed.

This RFC offers an arguably much simpler solution to the problem, by allowing the use of classes as “pseudo-namespaces”, which would immediately work with existing libraries of public static functions, and additionally would work with Composer (or any auto-loader) as-is.

Furthermore, existing classes with public static functions would be immediately supported without modification - e.g. without having to port all existing legacy code from public static to flat functions.

Proposal

This RFC proposes the following extensions to the “use function” statement.

Assume for the following examples a class as follows:

TODO

Backward Incompatible Changes

None.

Proposed PHP Version(s)

Next PHP 7.x.

RFC Impact

On ''call_user_func''

TBD

To ''Reflection''

TBD

To SAPIs

None.

To Existing Extensions

TBD

To Opcache

TBD

Future Scope

TBD

Proposed Voting Choices

TBD

Patches and Tests

None yet.

Implementation

None yet.

References

TODO

Rejected Features

TODO

rfc/use-static-function.1485451979.txt.gz · Last modified: 2017/09/22 13:28 (external edit)