严格标准错误 - 通过参考


Strict Standards Error - passing by reference

我不断收到此错误:

Strict Standards: "Only variables should be passed by reference in
/home/mydirectory/public_html/myfolder/modules/checkout/controllers/myfile.php
on line 65"

这是第 65 行的代码:

$stmt->bind_param(
  "iissds", 
  $this->auth->getInformation("id"), 
  $_POST["method"], 
  $transaction_id, 
  $Method->getTransactionID(), 
  $total_price, 
  serialize($_POST));

我确实尝试编辑我的php.ini并输入代码片段以忽略这些错误,但无济于事,我可能把它搞砸了,因为我对它相当陌生。

如果有人能告诉我如何严格证明它,那就太棒了!提前致谢

我猜你调用的bind_param函数是mysqli的bind_param。

如果我们看一下这个函数的定义,我们会看到变量是通过引用传递的:

 bool mysqli_stmt::bind_param ( string $types , mixed &$var1 [, mixed &$... ] )

&通过引用表示。

现在让我们看看您遇到的错误:

Only variables should be passed by reference

问题是你把函数调用的结果直接传递给bind_param,而只有变量应该通过引用传递。

要解决这个问题,您需要做的就是将这些值分配给变量并将其传递给函数,例如:

$id = $this->auth->getInformation("id");
...
$stmt->bind_param('iissds', $id, ...

有关参考文献的更多信息,请查看 php.net 文章"参考文献的作用":

http://php.net/manual/en/language.references.whatdo.php

希顿错误

在您的问题中,您提到隐藏这些消息。修复代码问题总是比禁止显示警告更好。

要调整显示的错误,请查看 PHP 的 error_reporting 函数。

如果你想显示除严格之外的所有内容,你可以这样做:

error_reporting(E_ALL ^ E_STRICT);

这也可以在 php.ini 配置文件中设置:

error_reporting = E_ALL ^ E_STRICT