更新4:
print_r( $data );
返回我在原始问题中发布的数据
但
print_r( $data->getAttributes() );
返回:
[namePerson/first] => Oshiro
[contact/email] => oshiro.wanen@gmail.com
[namePerson/last] => Wanan )
所以它不包含我在$data
更新3:
它似乎有一个getAttributes,所以我尝试了:
$data -> data -> getAttributes('data_identity')
但是得到错误:
[Tue Jul 12 09:01:17 2011] [error] [client ::1] PHP Fatal error: Call to a member function getAttributes() on a non-object in /var/www/page1.php on line 65
更新2:
我试过了两个:
$data -> get('data_identity')
$data -> data -> get('data_identity')
都给出了同样的错误:
[Tue Jul 12 08:46:26 2011] [error] [client ::1] PHP Fatal error: Call to a member function get() on a non-object in /var/www/page1.php on line 63
更新1:
如果我这样做:
$_SESSION['returned_array'] = array("id" => $openid);
print_r( $_SESSION['returned_array'] );
它返回我上面显示的数据。
然而,这样做:
$_SESSION['returned_array'] = array("id" => $openid['data:protected']['data_identity']);
print_r( $_SESSION['returned_array'] );
告诉我:
[Mon Jul 11 19:52:38 2011] [error] [client ::1] PHP Fatal error: Cannot use object of type LightOpenID as array in /var/www/page1.php on line 62
原始问题:
使用以下内容:
print_r( $data );
我明白了:
[returnUrl] => http://localhost/page1.php
[required] => Array ( )
[optional] => Array ( )
[verify_peer] =>
[capath] =>
[cainfo] =>
[identity:Lightdata:private] =>
[claimed_id:Lightdata:private] => https://www.google.com/accounts/o8/id?id=349fj398sdhf9h94eiwujf9843e9f398
[server:protected] => https://www.google.com/accounts/o8/ud
[version:protected] => 2
[trustRoot:protected] => http://localhost
[aliases:protected] =>
[identifier_select:protected] =>
[ax:protected] => 1
[sreg:protected] =>
[data:protected] => Array (
[data_ns] => http://specs.data.net/auth/2.0
[data_mode] => id_res
[data_op_endpoint] => https://www.google.com/accounts/o8/ud
[data_response_nonce] => 2011-07-05T18:04:58Z1Ctdh8tsgmlLrw
[data_return_to] => http://localhost/page1.php
[data_assoc_handle] => AOQobUflA4349fj398sdhf9h94eiwujf9843e9f3988RCX4lIqE
[data_signed] => op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle,ns.ext1,ext1.mode,ext1.type.namePerson_first,ext1.value.namePerson_first,ext1.type.contact_email,ext1.value.contact_email,ext1.type.namePerson_last,ext1.value.namePerson_last
[data_sig] => Z8OyG9w1349fj398sdhf9h94eiwujf9843e9f3982O/a349fj398sdhf9h94eiwujf9843e9f398iw=
[data_identity] => https://www.google.com/accounts/o8/id?id=349fj398sdhf9h94eiwujf9843e9f398
[data_claimed_id] => https://www.google.com/accounts/o8/id?id=349fj398sdhf9h94eiwujf9843e9f398
[data_ns_ext1] => http://data.net/srv/ax/1.0
[data_ext1_mode] => fetch_response
[data_ext1_type_namePerson_first] => http://axschema.org/namePerson/first
[data_ext1_value_namePerson_first] => Oshiro
[data_ext1_type_contact_email] => http://axschema.org/contact/email
[data_ext1_value_contact_email] => oshiro.wanen@gmail.com
[data_ext1_type_namePerson_last] => http://axschema.org/namePerson/last
[data_ext1_value_namePerson_last] => Wanen
如何仅获取数组的以下值?
[data_identity]
答案 0 :(得分:3)
$data['data']['data_identity'];
但这很可能是一个对象,所以你不应该这样做,而应该使用一个返回所需数据的对象的方法。你应该能够使用这样的东西:
$data->get('data_identity');
或$data->data->get('data_identity');
通常不允许访问受保护的方法或属性:
http://www.php.net/manual/en/language.oop5.visibility.php
要访问它,您需要特定的“获取”方法。
答案 1 :(得分:1)
输出似乎是对象的输出,而不是数组,属性data
是受保护的一,如果没有加入功能,你就无法访问它。
在你的对象中,应该有一些函数来获取['data']['data_identity']
的内容。
如果没有函数,您无法访问它的值,除非您正在扩展该类,否则您可以像parent::data['data_identity']
一样访问它。
根据您使用的输出和类,data
数组似乎用于内部操作,但是您可以通过data_identity
<获得$data->identity
的相同值/ p>
答案 2 :(得分:1)
我认为您的$ data是一个对象(这就是您拥有属性可见性的原因)。
所以,试试这个:
$data->getData()->data_identity
其中getData()
是受保护属性data