Calling a PHP function defined in another namespace without the prefix

前端 未结 3 2041
别跟我提以往
别跟我提以往 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:56

    I don't know an elegant solution, but...

    You can create wrapper functions that encapsulate the functions in the external namespace. This will let you keep your code readability...

    function assertThat($x, $y) { return h\assertThat($x, $y); }

提交回复
热议问题