note 108625 added to language.namespaces.importing
| From: | samuel dot roze at gmail dot com | Date: | Fri, 11 May 2012 13:34:43 +0000 |
| Subject: | note 108625 added to language.namespaces.importing | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187943@lists.php.net to get a copy of this message | ||
(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()
----
Server IP: 69.147.83.197
Probable Submitter: 83.145.84.150
----
Manual Page -- http://www.php.net/manual/en/language.namespaces.importing.php
Edit -- https://master.php.net/note/edit/108625
Del: integrated -- https://master.php.net/note/delete/108625/integrated
Del: useless -- https://master.php.net/note/delete/108625/useless
Del: bad code -- https://master.php.net/note/delete/108625/bad+code
Del: spam -- https://master.php.net/note/delete/108625/spam
Del: non-english -- https://master.php.net/note/delete/108625/non-english
Del: in docs -- https://master.php.net/note/delete/108625/in+docs
Del: other reasons-- https://master.php.net/note/delete/108625
Reject -- https://master.php.net/note/reject/108625
Search -- https://master.php.net/manage/user-notes.php