开发者

Call-time pass-by-reference has been deprecated, array_push error

I'm using a MysqliDb class and it gives this error:

"Deprecated: Call-time pass-by-reference has been deprecated in C:...\MySqlDb.php on line 101", 340, 348 and 375

where is a array_push function:

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

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

I removed the "&" and it work开发者_运维技巧ed but just for these /\ two, but not for these / two (giving a lot of errors)

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

and

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

The MysqliDb class can be found here: https://github.com/ajillion/PHP-MySQLi-Database-Class


array_push is equivalent to appending an element to an array. You can rewrite the line

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

to

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

in your case.


The E_DEPRECATED error is a warning btw. Passing by reference is still possible. To avoid the warning, you could alternatively force it with this clumsy workaround:

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

(It actually needs pass by reference for both params then.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜