dtbam62840 2019-08-02 19:30
浏览 90

在什么情况下PHP的错误抑制不适用于未定义的索引?

I'm using a library via composer that has code like this:

$data['video_id'] = @$data['video_id'] ?: $player['videoId'];

This line is causing a 500 error because $data['video_id'] is not defined. If I remove the @ symbol, I get the exception Notice: Undefined index: video_id. If I put back the @ symbol, the script simply dies immediately, and nginx returns a 500 status.

PHP's documentation says:

Warning: Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why.

It's possible this is happening here, but the error is not critical: it is a "notice", and according to that documentation, is a valid use for @.

I can always fork this library and fix the error myself, but I'd like to know why the suppression variable isn't working as intended.

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示