uqf0663
V2EX  ›  PHP

语法兼容 5.2 问题

  •  
  •   uqf0663 · Oct 13, 2016 · 2846 views
    This topic created in 3545 days ago, the information mentioned may be changed or developed.
    <?php
    class my_cls{
    function __construct(){
    $this->str=str_split('sfjhfsjfskdksdjkfskjsfkjsfkjfsfjvjhfjhv',1);
    }
    public function array_index($t){
    return array_search($t, $this->str);
    }
    public function test($str){
    for($i=0;$i<floor(strlen($str)/2);$i++){
    $arr = array_map("my_cls::array_index",str_split(substr($str,$i*2,2)));
    }
    }
    }




    以上代码在 PHP5.4 是正常的,但是不兼容 5.2

    请教一下 my_cls::array_index 应该怎么改才能兼容 PHP5.2 ?
    6 replies    2016-10-14 12:13:36 +08:00
    jfcherng
        1
    jfcherng  
       Oct 13, 2016   ❤️ 1
    可以試試 array($this, 'array_index')
    uqf0663
        2
    uqf0663  
    OP
       Oct 13, 2016
    @jfcherng 非常感谢,我自己琢磨了一下午,没想到解决起来这么简洁 ^_^
    surfire91
        3
    surfire91  
       Oct 13, 2016   ❤️ 1
    uqf0663
        4
    uqf0663  
    OP
       Oct 13, 2016
    @surfire91 感谢~
    Outshine
        5
    Outshine  
       Oct 14, 2016
    为毛还要兼容 5.2 。。。
    uqf0663
        6
    uqf0663  
    OP
       Oct 14, 2016
    @Outshine 买的空间,该空间商只有 5.2 。。。。。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   816 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 21:08 · PVG 05:08 · LAX 14:08 · JFK 17:08
    ♥ Do have faith in what you're doing.