0

Google 身份验证服务返回一个 php 对象(我们称之为 $Ticket)。它的价值是这样的

Google_LoginTicket Object ( [envelope:Google_LoginTicket:private] => Array ( [alg] => RS256 [kid] => 057d4167ee9b75e7b3a3fcc9c1ca17a14dab5044 ) )

现在我想访问 alg 的值,即“RS256”。

print_r ($Ticket->{'envelope:Google_LoginTicket:private'});

print_r 没有给出任何东西。

4

3 回答 3

2

Google_LoginTicket 有 getAttributes() 函数,它返回属性数组,你可以在源代码中检查这一点 https://github.com/sylvainw/GPlusGlobe/blob/master/src/auth/Google_LoginTicket.php

$attrs = $Ticket->getAttributes();
print_r($attrs["envelope"]);
于 2013-02-26T13:57:18.010 回答
0

您可以通过反射访问私有属性。但是,不建议这样做。这些主要是框架使用的功能。

相反,您应该搜索为您提供所需价值的方法。

var_dump(get_class_methods($Ticket));

通常,直接阅读 API 文档或源文件可以让您看到类中可用的方法。

于 2013-02-26T13:58:29.127 回答
0

实例变量是私有的envelope,所以你不能像那样访问它;您必须使用提供的方法

$attributes = $Ticket->getAttributes();

$envelope = $attributes['envelope'];
于 2013-02-26T13:59:49.950 回答