1

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 worked 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

Dharman
  • 30,962
  • 25
  • 85
  • 135
Silviu Claponea
  • 145
  • 1
  • 1
  • 5

1 Answers1

3

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.)

mario
  • 144,265
  • 20
  • 237
  • 291
  • 3
    The second half is bad advice. Call-time pass-by-reference has been killed in PHP 5.4 and the call_user_func_array loophole has been closed. – Artefacto Jul 03 '11 at 11:35
  • @mario As I understand it, the problem is the feature is a security risk (namely it allows interruption information leaks). – Artefacto Jul 03 '11 at 11:57
  • @mario: Still the second example looks quite superfluous to me, compared with the first one (regardless of deprecation policy). @Artefacto: I think the main point is in making function definitions more strict. – hakre Jul 03 '11 at 12:34
  • @hakre: Couldn't find much on it. The deprecation contradicts the previous RFC https://wiki.php.net/rfc/calltimebyref - which mentioned it originally for "code cleanliness". But if there is an actual ZendVM problem with it, then it's a bit more sensible than the CCP reasoning. (And anyway, there are more superfluous workarounds for the rare use cases..) – mario Jul 03 '11 at 12:43
  • in this particular case `array_push` can be replaced by `[] =`. but what about e.g. `array_unshift`? – user102008 Sep 01 '11 at 22:42
  • for Artefacto's point, here is a link to the relevant documentation: http://php.net/manual/en/function.call-user-func-array.php#refsect1-function.call-user-func-array-notes "This form of call-time pass by reference does not emit a deprecation notice, but it is nonetheless deprecated, and will most likely be removed in the next version of PHP." – user102008 Sep 01 '11 at 22:53