以下PHP函数产生此错误:解析错误:语法错误,意外'(',期待T_STRING或T_VARIABLE或'$',在此行:throw new ( '' . 'Illigal name for service name "' . $name . '" is given' );
有谁知道什么是错的?
function registerService($name, $provider) {
if (strlen( $name ) < 1) {
Exception;
throw new ( '' . 'Illigal name for service name "' . $name . '" is given' );
}
$this->_Services[$name] = $provider;
}
由于
答案 0 :(得分:1)
改变这个:
Exception;
throw new ( '' . 'Illigal name for service name "' . $name . '" is given' );
对此:
throw new Exception('Illegal name for service name "' .$name .'" is given' );
另外,通常你会在try catch块中抛出一个Exception:
try {
throw new Exception('Just testing');
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
//Output: Caught exception: Just testing