在下面的示例中,如果该类不存在,我想捕获错误并Null改为创建一个类.
但是,尽管我的try/catch语句,PHP只是告诉我Class 'SmartFormasdfasdf' not found.
如何让PHP捕获"找不到类"错误?
<?php
class SmartFormLogin extends SmartForm {
public function render() {
echo '<p>this is the login form</p>';
}
}
class SmartFormCodeWrapper extends SmartForm {
public function render() {
echo '<p>this is the code wrapper form</p>';
}
}
class SmartFormNull extends SmartForm {
public function render() {
echo '<p>the form "' . htmlentities($this->idCode) . '" does not exist</p>';
}
}
class SmartForm {
protected $idCode;
public function __construct($idCode) {
$this->idCode = $idCode; …Run Code Online (Sandbox Code Playgroud)