dongzhiji0814 2014-05-07 18:51
浏览 87
已采纳

PHP无效字符串索引会在某些服务器上导致错误,但在其他服

An invalid PHP string index usage that has been in place since 2008 today started causing an error. Debugging the reason for the invalid string index is not part of my question. The question is why does this only appear on certain servers?

Here is an example of the code:

$str = '0:828:555555';
$y = $str['id'];

The presence of the ['id'] appears to be the problem that causes the crash on one server but not on any of our production servers. So the invalid coding has been escaping for all these years.

The PHP levels and error_reporting levels unfortunately are not the same. The one that lets the error pass is 5.3.8. The one that has the error is 5.4.24. In addition, the 5.4.24 has E_STRICT but all the other settings are the same.

So I turned E_STRICT off and the error still happens.

The simplistic answer is "the PHP levels are not the same." But the error has in place for a long time, and so has the difference in PHP levels.

Any ideas on the cause of the server-dependent crash?

  • 写回答

1条回答 默认 最新

  • dongshan1959 2014-05-07 18:57
    关注

    From the manual:

    "As of PHP 5.4 string offsets have to either be integers or integer-like strings, otherwise a warning will be thrown. Previously an offset like "foo" was silently cast to 0."

    http://www.php.net/manual/en/language.types.string.php

    Probably PHP was recently updated to 5.4 on some of your servers, or you only recently noticed this error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c