yoke123
V2EX  ›  PHP

关于 php7.1 的一些疑惑 求解答

  •  
  •   yoke123 · Jun 2, 2017 · 3893 views
    This topic created in 3330 days ago, the information mentioned may be changed or developed.

    如图所示:

    为什么结果输出不一样? 求解答

    参考资料:

    Fixed bug #71266 (Missing separation of properties HT in foreach etc)

    https://bugs.php.net/bug.php?id=73792

    11 replies    2017-06-13 17:57:51 +08:00
    muziyue
        1
    muziyue  
       Jun 2, 2017
    $tmp 是 String 啊,有什么问题
    helone
        2
    helone  
       Jun 2, 2017   ❤️ 1
    我猜测是 7.0 之前版本有类型隐形转换把,$tmp[$k]的时候自动把$tmp 转换成 array 了,7.1 没有做类型转换,所以输出就是 string 了
    yoke123
        3
    yoke123  
    OP
       Jun 2, 2017
    @helone #2 隐式转换吗? 看来是这个问题了 谢谢解答
    shoaly
        4
    shoaly  
       Jun 2, 2017
    这个时候 就多么的希望有一个 java 的编译检查, String 对象无法转换成 Array.
    muziyue
        5
    muziyue  
       Jun 2, 2017   ❤️ 1
    Applying the empty index operator to a string (e.g. $str[] = $x) throws a fatal error instead of converting silently to array.

    7.1 新特性,现在字符串不会自动转换为数组,跟你发的链接没什么关系
    U7Q5tLAex2FI0o0g
        6
    U7Q5tLAex2FI0o0g  
       Jun 2, 2017   ❤️ 1
    参考:
    http://php.net/manual/zh/migration71.incompatible.php#migration71.incompatible.empty-string-index-operator

    字符串不再支持空索引操作符 The empty index operator is not supported for strings anymore ¶
    对字符串使用一个空索引操作符(例如$str[] = $x )将会抛出一个致命错误, 而不是静默地将其转为一个数组。
    yoke123
        7
    yoke123  
    OP
       Jun 2, 2017
    @muziyue #5
    @littleylv #6
    懂了 谢谢解答
    Felldeadbird
        8
    Felldeadbird  
       Jun 2, 2017
    学习到了。
    run2
        9
    run2  
       Jun 2, 2017
    觉得挺好,是时候 brew install homebrew/php/php71 了 ( macOS 本地测试环境)
    ichou
        10
    ichou  
       Jun 3, 2017 via iPhone
    看来 7.1 改动还是挺大的,没记错的话,Array 基本就是重写了
    redrain2016
        11
    redrain2016  
       Jun 13, 2017
    越来越强类型了!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   976 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 18:55 · PVG 02:55 · LAX 11:55 · JFK 14:55
    ♥ Do have faith in what you're doing.