【问题标题】:stdClass could not be converted to stringstdClass 无法转换为字符串
【发布时间】:2018-11-09 17:45:31
【问题描述】:

我有一个带有字符串的属性的对象。

class Authentication
{
    public $secretKey = "secret";
}

当我在 jwt decode 中使用变量时,它会输出:

Object of class stdClass could not be converted to string

我从未将该变量设为对象。

这是我对代码所做的:

$authentication = new Authentication();

$token = array();
$token['id'] = "username_here";

$jwtToken = jwt::encode($token, $authentication->getKey());
echo jwt::decode($jwtToken, $authentication->getKey());

【问题讨论】:

  • jwt::decode 你刚刚做了一个对象。
  • 那么你的问题是什么?
  • 使用 print_r 检查 jwt::decode($jwtToken, $authentication->getKey()); 的输出
  • @Efekan 很抱歉没有这么说。问题是它为什么会输出该错误。
  • @JonStirling 干杯,没有意识到这一点。

标签: php jwt


【解决方案1】:

问题是我试图回显作为对象的返回值。本来我以为问题出在变量上。

【讨论】:

    猜你喜欢
    • 2011-04-06
    • 2018-10-19
    • 2020-03-16
    • 2021-11-10
    • 2014-06-12
    • 1970-01-01
    相关资源
    最近更新 更多