Listing 6.17 Using a namespace
<?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;
?>