PHP RFC: Importing namespaced functions

Introduction

PHP offers the ability to import namespaces and types (classes/interfaces/traits) via the use statement. This capability however does not exist for functions. As a result, working with namespaced functions is rather cumbersome.

A function can only be referenced without fully qualifying it, if the calling code is in the same namespace as the function:

You cannot import the function directly. PHP does not currently support that.

Proposal

The proposal is to combine existing keywords to a new sequence that allows importing functions into a namespace. This should make namespaced functions less of a pain to use and discourage placing them in the global namespace.

Since functions and classes are in separate namespaces, it is not feasible to use the use keyword for both, as it would likely result in conflicts and overhead.

Instead of introducing a new keyword, it would be possible to combine use and function to a sequence. This new use function combo would work as follows:

The call to strlen is no longer ambiguous. non_existent is no longer looked up in the global namespace.

Why is "use function" needed instead of just "use"?

In PHP, functions and classes are stored in separate namespaces. A function `foo\bar` and a class `foo\bar` can co-exist, because it is possible to infer from the context if the symbol is used as a class or a function: