首页 > 解决方案 > PHP 错误:未定义的属性:当 property_exists 为 true 时 stdClass::$access_token

问题描述

我在使用 PHP5 的身份验证回调中收到以下错误:

Undefined property: stdClass::$access_token

这是代码:

$result = curl_exec($ch);
$data = json_decode($result);


var_dump(property_exists($data, 'access_token'));
var_dump($data);
var_dump($data->access_token);

$token = $data->access_token;

这是该代码的结果:

bool(true) 
object(stdClass)#1 (5) { ["access_token"]=> string(36) "pretend-code-is-here" ["token_type"]=> string(6) "bearer" ["expires_in"]=> int(3600) ["refresh_token"]=> string(36) "pretend-code-is-here" ["scope"]=> string(8) "identity" } 
string(36) "pretend-code-is-here"

该代码与特定的 var_dump 匹配,但我无法将其分配给 $token 而不会出现该错误,并且我无法在以下请求中使用它。

标签: php

解决方案


推荐阅读