• [php-error-report]PHP Strict Standards: Only variables should be passed by reference


    // 报错代码:PHP Strict Standards:  Only variables should be passed by reference
    
    $arr_userInfo['im_nation_cn'] = array_shift(preg_split('/,/' , $arr_userInfo['im_nation_cn']);
    
    // 修改后,不再报错的代码,原因是 PHP 自带的函数 array_shift()是以引用的方式来传参,而引用传参,只能是一个变量
    $arr_im_nation_cn = preg_split('/,/' , $arr_userInfo['im_nation_cn']);
    $arr_userInfo['im_nation_cn'] =  array_shift($arr_im_nation_cn) ;
    
    // Google 出来的原解答 , 原文链接:http://stackoverflow.com/questions/2354609/strict-standards-only-variables-should-be-passed-by-reference
    /*
    Consider the following code:
    
    error_reporting(E_STRICT);
    class test {
        function test_arr(&$a) {
            var_dump($a);   
        }
        function get_arr() {
            return array(1,2);  
        }
    }
    
    $t= new test;
    $t->test_arr($t->get_arr());
    This will generate the following output:
    
    Strict Standards: Only variables should be passed by reference in test.php on line 14
    array(2) {
      [0]=>
      int(1)
      [1]=>
      int(2)
    }
    The reason? The test::get_arr() method is not a variable and under strict mode this will generate a warning. This behavior is extremely non-intuitive as the get_arr() method returns an array value.
    
    To get around this error in strict mode either change the signature of the method so it doesn't use a reference:
    
    function test_arr($a) {
        var_dump($a);  
    }
    Since you can't change the signature of array_shift you can also use an intermediate variable:
    
    $inter= get_arr();
    $el= array_shift($inter);
    */
    
  • 相关阅读:
    系统角色权限问题
    解析JQuery Ajax
    JavaScriptSerializer序列化时间处理
    Javascript加载talbe(包含分页、数据下载功能)
    代理模式
    工厂模式
    单例模式
    Oracle内置函数
    Oracle大数据SQL语句优化
    Oracle大数据查询优化
  • 原文地址:https://www.cnblogs.com/shuman/p/5217778.html
Copyright © 2020-2023  润新知