开发者

Accessing deeper data in an array

开发者 https://www.devze.com 2023-03-19 06:14 出处:网络
UPDATE 4: print_r( $data ); returns the data I posted in the original question, but print_r( $data->getAttributes() );

UPDATE 4:

print_r( $data );

returns the data I posted in the original question,

but

print_r( $data->getAttributes() );

returns:

[namePerson/first] => Oshiro 
[contact/email] => oshiro.wanen@gmail.com 
[namePerson/last] => Wanan )

so it does not contain the data_identity I am after which is in $data

UPDATE 3:

It seems to have an getAttributes, so I tried:

$data -> data -> getAttributes('data_identity')

But get the error:

[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

UPDATE 2:

I've tried both:

$data -> get('data_identity')
$data -> data -> get('data_identity')

both give the same error:

[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

UPDATE 1:

If I do this:

$_SESSION['returned_array'] = array("id" => $openid);
print_r( $_SESSION['returned_array'] );

It returns the data as I have shown above.

However, doing this:

$_SESSION['returned_array'] = array("id" => $openid['data:protected']['data_identity']);
print_r( $_SESSION['returned_array'] );

give me:

[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

ORIGINAL QUESTION:

Using the following:

print_r( $data );

I get:

[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=349fj398sdhf9h9开发者_如何学C4eiwujf9843e9f398
    [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

How do I get the following value of the array only?

[data_identity]


$data['data']['data_identity'];

But this most likely is an object so you shouldn't do that instead you should use a method of the object that will return the required data. You should be able to use something like that:

$data->get('data_identity'); or $data->data->get('data_identity');

Normally ou're not allowed to access protected method or property:

http://www.php.net/manual/en/language.oop5.visibility.php

to access it you'll need specific 'get' method.


The output seems to be that of an object, and not an array, and the attribute data is a protected one, thus you can't access it without an accession function.

In your object, there should be some function to get the contents of ['data']['data_identity'].

Without a function, you can't access it's value, unless you are extending that class, then you can access it like parent::data['data_identity'].


Update

Based on the output and the class you are using, the data array seems to be used for the internal operations, however you can get the same value of data_identity via $data->identity


I think your $data is an object (this is why you have the visibility of the attributes). So, try this : $data->getData()->data_identity

where getData() is an accessor of your protected attribute data

0

精彩评论

暂无评论...
验证码 换一张
取 消