What is the equivalent of C#’s using Name.Space; statement to make all classes of that namespace available in the current file? Is this even possible with PHP?
What I’d like (but does not work):
<?php
# myclass.php
namespace Namespace;
class myclass {
}
?>
<?php
# main.php
include 'myclass.php'
use Namespace;
new myclass();
?>
There is none. In PHP the interpreter won’t know all classes which possibly might exist (especially due to the existence of __autoload) so the run-time would running into many conflicts. Having something like this:
There might e a Foo\Exception which should be
__autoloaded — PHP can’t know.What you can do is import a sub-namespace:
or with alias: