Calling a PHP function defined in another namespace without the prefix

前端 未结 3 2009
别跟我提以往
别跟我提以往 2021-01-01 09:02

When you define a function in a namespace,

namespace foo {
    function bar() { echo \"foo!\\n\"; }
    class MyClass { }
}

you must specif

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-01 09:36

    PHP 5.6 will allow to import functions with the use keyword:

    namespace foo\bar {
        function baz() {
            echo 'foo.bar.baz';
        }
    }
    
    namespace {
        use function foo\bar\baz;
        baz();
    }
    

    See the RFC for more information: https://wiki.php.net/rfc/use_function

提交回复
热议问题