This is an old revision of the document!
PHP RFC: Static "use function"
- Version: 0.1
- Date: 2016-01-26
- Author: Rasmus Schultz, email@example.com
- Status: Draft
- First Published at: http://wiki.php.net/rfc/use-static-function
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.
This RFC proposes the following extensions to the “use function” statement.
Assume for the following examples a class as follows:
Backward Incompatible Changes
Proposed PHP Version(s)
Next PHP 7.x.
To Existing Extensions
Proposed Voting Choices
Patches and Tests