zoukankan      html  css  js  c++  java
  • [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);
    */
    
  • 相关阅读:
    C#Mvc批量删除
    axure中使用HighCharts模板制作统计图表
    中继器的使用——搜索/分页/排序
    中继器的使用 —— 关联/增加/删除/修改数据
    axure母版使用实例之百度门户
    jdbc参数传递
    软件测试的原则
    linux中使用top获取进程的资源占用信息
    性能测试关键指标介绍
    怎样成为一个合格的测试工程师
  • 原文地址:https://www.cnblogs.com/shuman/p/5217778.html
Copyright © 2011-2022 走看看