Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更新旧的php代码。使用php<;5.4.0但不向上_Php_Arrays_Reference - Fatal编程技术网

更新旧的php代码。使用php<;5.4.0但不向上

更新旧的php代码。使用php<;5.4.0但不向上,php,arrays,reference,Php,Arrays,Reference,我有很多这样的代码行。 调用('someCustomFunctionName',数组($paramA,¶mB,$paramC)) 我已经更新了我的服务器php版本,它不再工作了 以下是用于测试的简化代码。预期输出:$b为真,$c为2 function call($function, $param_arr = array()) { # Lots of code here. return function_exists($function) ? call_user_fu

我有很多这样的代码行。 调用('someCustomFunctionName',数组($paramA,¶mB,$paramC))

我已经更新了我的服务器php版本,它不再工作了

以下是用于测试的简化代码。预期输出:$b为真,$c为2

function call($function, $param_arr = array())
{   
    # Lots of code here.
    return function_exists($function) ? call_user_func_array( $function, (array) $param_arr) : '';
}

function test_a($a, $b, $c)
{
    if($a['a'] == 1)
    {
        $b = true;
        $c++;
    }
}

$a = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4);
$b = false;
$c = 1;

call('test_a', array($a, &$b, &$c));

if($b)
{
    print '$b is true';
}
else{
    print '$b is false';
}
print '<br>';
print $c;
函数调用($function,$param\u arr=array())
{   
#这里有很多代码。
返回函数_exists($function)?调用_user_func_array($function,(array)$param_arr):“”;
}
功能测试a($a,$b,$c)
{
如果($a['a']==1)
{
$b=正确;
$c++;
}
}
$a=数组('a'=>1,'b'=>2,'c'=>3,'d'=>4);
$b=假;
$c=1;
调用('test_a',数组($a,&$b,&$c));
如果有的话(b美元)
{
打印“$b为真”;
}
否则{
打印“$b为假”;
}
打印“
”; 打印$c;
问题出在
test_a()
函数中。如果向数组提供两个引用
$b
$c
,则该函数不接受引用值,而是创建一个副本

解决方案很简单:

function test_a($a, &$b, &$c){
  if($a['a'] == 1){
    $b = true;
    $c++;
  }
}

服务器日志中有什么错误?或者您只是没有得到预期的输出?这是一个“通过引用传递”问题:您通过值传递,但仍然希望这些变量像通过引用传递一样被更新。“它不起作用”从来没有在任何时间任何地方帮助过任何人获得代码方面的帮助。您需要在细节上更加具体:您得到了什么确切的行为和错误?在服务器php升级之前,一切都正常。没有错误。预期的$b值应该为真,我得到的是假。预期的$c值应为2 i get 1
错误报告(E_ALL);ini_集('display_errors','1')