php中namespace使用过程
//test2.php <?php namespace Pj\Test; function test($val){ if(is_numeric($val)){ return $val+12; } die("参数不是数字!"); }; ?>
//test1.php <?php header('Access-Control-Allow-Origin:*'); require_once dirname(__FILE__)."/test2.php";//1 use \Pj\Test as NowSpace;//2 $result = NowSpace\test(23);//3 echo $result; ?>
test1.php和test2.php父目录相同
1.require引入文件
2.导入命名空间(可用as定义代替该空间)
3.使用空间下的代码
---Pjer
浙公网安备 33010602011771号