<?php namespace LIB; include 'test.php';//引入带命名空间的文件 include '__init__.php';//引入公共函数 class MySQL {} class SQLite {} function show() { return "111"; } namespace LIB_EXTRA; use LIB as T;//声明使用 空间LIB class MScrypt {} $a = new MScrypt(); function show() { return "ad"; } use foo as F; var_dump( get_class($a), Tshow(), Fabc(), fooabc(),//直接使用命名空间调用函数 common()//调用公共空间的函数 );
string 'LIB_EXTRAMScrypt' (length=17) string '111' (length=3) int 151 int 151 string 'common' (length=6)
test.php
<?php namespace foo; class Xyz {} function abc () { return 151; }
__init__.php
<?php function common() { return "common"; }