Does PHP have some sort of using namespace of C++? (So you don’t have to write any namespace before your calls)
I have defined a function within:
namespace \Project\Library {
function hello() {
}
}
Another file.php:
use \Project\Library;
hello(); //> Error: Call to undefined function hello()
PS.
I know I could use use \Project\Library as L;
And then do L\hello();
I want to avoid L\ too.
Edit
I answer myself: you cannot do it. And that sucks imo (this is the first thing I don’t like of PHP).
Edit2
To be clear: If hello() was a class I could call it directly using use. The problem it is that is a simple function so I have to write its namespace. This is a little mindfucking of PHP.
Maybe we can consider this a bug and open a ticket?
Since PHP 5.3.0 it supports syntax
use ... as:Also guessing from manual using
usedirectly (withoutas Another) is not possible (it’s not mentioned in manual).You may be able to use some hack like class factory or workaround via autoloader but simple and direct answer is “it’s not possible”. 🙁