Namespaces can be imported with the use operator, e.g.
myapp2.php:
1 2 3 4 5 6 7 8 9 10 11 |
<br /> &lt;?php<br /> use AppLib2;<br /> require_once('lib1.php');<br /> require_once('lib2.php');<br /> header('Content-type: text/plain');<br /> echo Lib2MYCONST . &quot;n&quot;;<br /> echo Lib2MyFunction() . &quot;n&quot;;<br /> echo Lib2MyClass::WhoAmI() . &quot;n&quot;;<br /> ?&gt;</p> <p> |
Any number of use statements can be defined or you can separate individual namespaces with a comma. In this example we have imported the AppLib2 namespace. We still cannot refer directly to MYCONST, MyFunction or MyClass because our code is in the global space and PHP will look for them there. However, if we add a prefix of ?Lib2?, they become qualified names; PHP will search through the imported namespaces until it finds a match.
result:
1 2 3 4 5 6 |
</p> <p>view plainprint?<br /> AppLib2MYCONST<br /> AppLib2MyFunction<br /> AppLib2MyClass::WhoAmI</p> <p> |
Elizabete
Thanks! great web site. thank you for the information this site is amazing. very well developed with great information.
Regards
-Elizabete