【发布时间】:2017-08-28 14:55:07
【问题描述】:
我有这门课
namespace core;
class Entity {
private $type;
public function __construct($type, $source=null){
if($this::isValidType($type)){
$this->type = $type;
}else{
throw new Exception("'".$type."' is not a valid type of entity.");
}
}
private static function isValidType($type){
return in_array($type, array(
'Thing',
));
}
}
然后我使用这个代码:
$thing = new core\Entity('Not a Thing');
我希望它显示 "Not a Thing" is not a valid Type of entity 但我却得到了
致命错误:在第 {line} 行的 {root/to/my/file} 中找不到类“core\Exception”。
我错过了什么吗?
【问题讨论】:
标签: php class exception constructor exception-handling