相关疑难解决方法(0)

为什么PHP没有捕获"未找到类"错误?

在下面的示例中,如果该类不存在,我想捕获错误并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)

php try-catch

27
推荐指数
4
解决办法
2万
查看次数

标签 统计

php ×1

try-catch ×1