note 108625 deleted from language.namespaces.importing by peehaa
| From: | peehaa@php.net | Date: | Sun, 28 Apr 2019 11:02:17 +0000 |
| Subject: | note 108625 deleted from language.namespaces.importing by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210859@lists.php.net to get a copy of this message | ||
Note Submitter: samuel dot roze at gmail dot com
----
(All the backslashes in namespaces are slashes because I can't figure out how to post
backslashes here.)
You can have the same "use" for a class and a namespace. For example, if you have these
files:
<?php
// foo/bar.php
namespace foo;
class bar
{
public function __toString ()
{
return 'foo\bar\__toString()';
}
}
?>
<?php
// foo/bar/MyClass.php
namespace foo/bar;
class MyClass
{
public function __toString ()
{
return 'foo\bar\MyClass\__toString()';
}
}
?>
In another namespace, you can do:
<?php
namespace another;
require_once 'foo/bar.php';
require_once 'foo/bar/MyClass.php';
use foo/bar;
$bar = new bar();
echo $bar."\n";
$class = new bar/MyClass();
echo $class."\n";
?>
And it will makes the following output:
foo\bar\__toString()
foo\bar\MyClass\__toString()