不推荐使用call-time pass-by-reference,array_push错误

时间:2011-07-03 11:22:43

标签: php mysql oop

我正在使用MysqliDb类,它会出现此错误:

  

“已弃用:在C:... \ MySqlDb.php第101行,340,348和375

已弃用调用时间传递引用

其中是array_push函数:

array_push($params, &$bindParams[$prop]);

array_push($this->_bindParams, &$tableData[$prop]);

我删除了“&”它只是为了这些/ \两个, 但不是这些/两个(给出了很多错误)

if($hasConditional) {
            if ($this->_where) {
                $this->_bindParams[0] .= $this->_whereTypeList;
                foreach ($this->_where as $prop => $val) {
                    array_push($this->_bindParams, &$this->_where[$prop]);
                }
            }   
        }

while ($field = $meta->fetch_field()) {
            array_push($parameters, &$row[$field->name]);
        }

可以在此处找到MysqliDb类:https://github.com/ajillion/PHP-MySQLi-Database-Class

1 个答案:

答案 0 :(得分:3)

array_push相当于将一个元素附加到数组中。你可以重写一行

     array_push($this->_bindParams, &$this->_where[$prop]);

     $this->_bindParams[] =  & $this->_where[$prop];

在你的情况下。


E_DEPRECATED错误是一个警告btw。通过引用传递仍然是可能的。为了避免警告,您可以使用这种笨拙的解决方法强制它:

call_user_func_array("array_push", array(&$this->_bindParams, &$this->_where[$prop]));

(实际上它需要通过参考传递两个参数。)

相关问题