dongwende1984 2010-07-29 16:27
浏览 50
已采纳

如何判断PHP致命错误何时真的是一个隐藏的语法错误,何时发生?

Considering the following PHP class:

class someObject {
    public function broken(){
        return isset($this->something()) ? 'worked' : 'didnt';
    }

    public function something(){
        return true;
    }

    public function notBroken(){
        print('worked');
    }
}

Let's say I now do:

$obj= new someObject();
$obj->broken();

Considering you can't pass a function call to isset(), (it's by-reference), I expect this to fail with a fatal error: PHP Fatal error: Can't use method return value in write context This is fine, and expected.

However, let's say I now do:

$obj= new someObject();
$obj->notBroken();

Considering I'm not hitting the broken() anywhere in this execution, and the error in broken() is a Fatal Error (and not a Parse error), I wouldn't expect the normal output of "worked". FALSE! It still generates the Fatal Error.

Question:

Aside from just not writing code that has errors, are there any other errors that are not Parse Errors but still trigger a runtime error? I only know about: PHP Fatal error: Can't use method return value in write context. Is there any way to detect these errors? Is there a special name for this type of error?

  • 写回答

2条回答 默认 最新

  • douchen2011 2010-08-09 18:19
    关注

    The reason for this specific behaviour is probably that isset() is a language construct and not a normal function that gets interpreted at runtime. So it stands to reason this is kind of a parse error.

    I have no deep insight in this though, and I don't know whether this class of errors has a specific name.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答