![第14节--命名空间 -- Classes and Objects in PHP5 [14]](http://img.win8xp.cn/noimg.jpg)
|            
第十四节--命名空间 <?php    namespace core_php:utility    {        class textEngine        {            public function uppercase($text) //大写            {                return(strtoupper($text));            }        }        //make non-OO interface 建立一个非OO的接口        function uppercase($text)        {            $e = new textEngine;            return($e->uppercase($text));        }    }    //test class in namespace 测试命名空间中的类    $e = new core_php:utility::textEngine;    print($e->uppercase("from object") . "<br>");    //test function in namespace 测试命名空间中的函数    print(core_php:utility::uppercase("from function") . "<br>");    //bring class into global namespace 把类导入全局命名空间    import class textEngine from core_php:utility;    $e2 = new textEngine; ?> Import语句把命名空间中的某个部份导入全局的命名空间. 要导入单一的命名空间的成员,可以指定类型为constant,function或class,接着写上成员的名称; //如import class XXX 如果你想导入某一特定类型的所有成员,你可以用*来代替名称; //如 import constant * 导入所有常量 如果你想导入所有类型的所有成员,用*即可. //如 import * 在成员之后,用from关键字加上命名空间的名称. //如 import class textEngine from core_php:utility; 总之你要写成像import * from myNamespace或 import class textEngine from core_php:utility这样的语句,就像例6.17中那样.  | 
温馨提示:喜欢本站的话,请收藏一下本站!