rfc:use_function

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:use_function [2013/07/19 16:42] – [PHP RFC: Importing namespaced functions] bump version to 1.0, change status to Under Discussion igorwrfc:use_function [2013/07/22 13:05] – [Changelog] formatting igorw
Line 1: Line 1:
 ====== PHP RFC: Importing namespaced functions ====== ====== PHP RFC: Importing namespaced functions ======
  
-  * Version: 1.0+  * Version: 1.0.1
   * Date: 2013-05-02   * Date: 2013-05-02
   * Author: Igor Wiedler, igor@wiedler.ch   * Author: Igor Wiedler, igor@wiedler.ch
Line 122: Line 122:
  
 The call to **strlen** is no longer ambiguous. **non_existent** is no longer looked up in the global namespace. 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:
 +
 +<code php>
 +namespace foo {
 +    function bar() {}
 +    class bar {}
 +}
 +
 +namespace {
 +    foo\bar(); // function call
 +    new foo\bar(); // class instantiation
 +    foo\bar::baz(); // static method call on class
 +}
 +</code>
 +
 +If **use** were changed to support functions as well, it would introduce BC breaks.
 +
 +An example:
 +
 +<code php>
 +namespace {
 +    function bar() {}
 +}
 +
 +namespace foo {
 +    function bar() {}
 +}
 +
 +namespace {
 +    use foo\bar;
 +    bar();
 +}
 +</code>
 +
 +The behaviour changed, when **use** was changed. Depending on your PHP version, a different function will be called.
  
 ==== Function autoloading ==== ==== Function autoloading ====
Line 165: Line 203:
  
 - None. - None.
 +
 +===== Changelog =====
 +
 +  * 2013-07-22 1.0.1 FAQ "why 'use function'?"
 +  * 2013-07-19 1.0.0 First version published for discussion
rfc/use_function.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1