“还不允许属性访问";使用准备好的语句时发出警告 [英] "Property access is not allowed yet" warning when using prepared statement

查看:61
本文介绍了“还不允许属性访问";使用准备好的语句时发出警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用AES_ENCRYPT()编码密码来进行登录.但是在尝试实现这些代码时,我从 xdebug 发出了一些警告:

I'm trying to make a log in system by using AES_ENCRYPT() to encode my password. But I have some warning from xdebug when trying to implement these codes:

...
$key = 'd0gis=SUPER-cute';
$sql = "SELECT * FROM `users2` WHERE username = ? AND pwd = AES_ENCRYPT(?, ?)";
$stmt = $conn->stmt_init();
$stmt->prepare($sql);
$stmt->bind_param('sss', $username, $password, $key);
$stmt->execute();
$stmt->store_result();
...

当调试器遇到第8行或$stmt->prepare($sql);行时,来自 xdebug 的6个相同的警告表会显示:

When the debugger meets line 8 or $stmt->prepare($sql);, 6 same warning tables from xdebug says:

(!)警告:main():在第8行的D:\ xampp \ htdocs \ learnphp \ includes \ authenticate_mysqli.inc.php中尚不允许属性访问

(!) Warning: main(): Property access is not allowed yet in D:\xampp\htdocs\learnphp\includes\authenticate_mysqli.inc.php on line 8

$stmt中的error属性为空,我没有真正的问题,但是我只想知道导致此警告消息出现的原因.

The error property in $stmt is empty and I have no real problem, but I just want to know what cause this warning messages to appear.

通过Google搜索此警告消息,但未找到任何解决方案:

Googled this warning message but didn't find any solution:

  1. 使用准备好的语句进行更新查询
  2. http://php.net/manual/en/mysqli -stmt.param-count.php
  1. UPDATE query with prepared statements
  2. http://php.net/manual/en/mysqli-stmt.param-count.php

推荐答案

我相信我在下面描述的问题是OP描述的问题的原因,但是由于我在答案中描述的问题并未产生确切的信息同样的错误消息,我不再确定这是最佳答案.

I believe the issue I describe below is the cause of the issue the OP describes, however since the problem I describe in my answer does not produce the exact same error message, I am no longer sure this is the best answer.

此外,我在PHP docs评论部分中注意到了这一点:

Also, I noticed this from the PHP docs comment section:

此参数(以及mysqli_stmt中的任何其他参数) 将显示错误消息不允许访问属性 还没有",如果该语句准备不当,或者在以下时间未准备 全部.

This parameter (and presumably any other parameter in mysqli_stmt) will raise an error with the message "Property access is not allowed yet" if the statement was not prepared properly, or not prepared at all.

为防止这种情况,请务必确保返回"prepare"的值 在访问这些属性之前,该语句为true.

To prevent this, always ensure that the return value of the "prepare" statement is true before accessing these properties.

原始答案: 当您尝试将某些对象(类的实例)评估为字符串时,会发生此警告.

Original answer: This warning occurs when you try to evaluate certain objects (an instance of a class) as a string.

您的调试器/IDE试图评估一个变量($ stmt),可能在监视列表或调用堆栈中,并且不能将其评估为字符串.

Your debugger/IDE is trying to evaluate one of your variables ($stmt), maybe in a watch list or call stack, and it cannot be evaluated as a string.

如果对变量执行print_r,则会得到相同的错误,因为PHP无法将其转换为字符串.

If you do print_r on the variable you will get the same error, because PHP cannot turn it into a string.

在您的情况下,PHP无法将$ stmt转换为字符串.

In your case, it is the $stmt that PHP cannot turn into a string.

将此代码放在第7行,您将在此处看到错误:

Put this code on line 7 and you will see the error there:

print_r($stmt);

有些旁注:我最近从未遇到过此问题.最近,我得到了很多东西.为什么php不跳过那些无法访问的属性并打印其余的属性?我相信这与属性的范围或getter/setter的使用有关,但我还不确定.当我弄清楚那一部分时,我会更新.

Somewhat side note: I never had this issue before recently. Lately I've been getting it a lot. Why doesn't php just skip the inaccessible properties and print the rest? I believe it has to do with the scope of the properties or the use of getters/setters but I am not quite sure yet. I will update when I figure that part out.

来自官方PHP文档: ( http://php.net/manual/en/language. oop5.magic.php#object.tostring )

__ toString()方法允许类决定其反应方式 当它被视为字符串时.例如,echo $ obj;将要 打印.此方法必须返回一个字符串,否则将是致命的 发出E_RECOVERABLE_ERROR级别错误...

The __toString() method allows a class to decide how it will react when it is treated like a string. For example, what echo $obj; will print. This method must return a string, as otherwise a fatal E_RECOVERABLE_ERROR level error is emitted...

...值得注意的是,在PHP 5.2.0之前的__toString()方法 仅在与回显或打印直接结合使用时才被调用. 从PHP 5.2.0开始,可以在任何字符串上下文中调用它(例如,在printf()中 使用%s修饰符),但不能在其他类型的上下文中使用(例如,使用%d 修饰符).从PHP 5.2.0开始,转换不带__toString()的对象 字符串方法将导致E_RECOVERABLE_ERROR.

...It is worth noting that before PHP 5.2.0 the __toString() method was only called when it was directly combined with echo or print. Since PHP 5.2.0, it is called in any string context (e.g. in printf() with %s modifier) but not in other types contexts (e.g. with %d modifier). Since PHP 5.2.0, converting objects without __toString() method to string would cause E_RECOVERABLE_ERROR.

这篇关于“还不允许属性访问";使用准备好的语句时发出警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆