namespace www\user\center;
use ReflectionClass;
use ReflectionMethod;/**
* 判断载入页面
* @author Mr.Lee
*
*/
final class userCenter {
private static $array = array(
"teamcode" => "teamCode",
"myorder" => "my_order"
);
static function exec() {
if (!isset($_GET['rid'])) {
member::exec();
echo ""; // 右侧主框架跳转
return;
} else {
$key = $_GET ["rid"];
if (array_key_exists($key, self::$array)) {
$class = new ReflectionClass("www\\user\\center\\".self::$array [$key]);
$method = $class->getMethod("exec");
$method->invoke($class->newInstance());
} else {
header("Location:pay/cart"); // 化妆品购物车
}
}
}
}
18行代码中 if (!isset($_GET['rid'])) 理论上是可以换成if (is_null($_GET['rid'])),但实际应用中,如果未使用$_GET方法取得变量rid时,23行代码$key = $_GET ["rid"];就会报错,虽然页面可以运行,但错误总是存在的。如果使用!isset($_GET['rid'])来判断就不会出现这个问题了。
对于使用smarty模板的项目,如果因rid这个值找不到而报错,并不影响页面内容,但会影响样式。原因就是有一个隐藏的警告输出到了某个样式里面。