Getting this error when I put use Blog; at the top.
Warning: The use statement with non-compound name ‘Blog’ has no effect
in…
Blog is my namespace in which I have 3 classes: Article, List and Category and a few functions.
If I change my statememnt to use Blog\Article; then it works…
Can’t I just specify the namespaces I want to use? Do I need to provide classes?
What if I have functions within that namespaces? When I call them outside of the namespace, I’m forced to prepend \Blog\ to each one’s name…
PHP’s
useisn’t the same as C++’susing namespace; it allows you to define an alias, not to “import” a namespace and thus henceforth omit the namespace qualifier altogether.So, you could do:
… to shorten it, but you cannot get rid of it entirely.
Consequently,
use Blogis useless, but I believe you could write:Note that you must use a leading
\here to force the parser into knowing thatReallyLongNSNameis fully-qualified. This isn’t true forBlog\Article, which is obviously already a chain of namespaces: