Page 1 of 1

How to address a numericly named object member variable

Posted: Wed Mar 11, 2009 6:36 am
by Surfr
Using a JSON lib it is creating a resultset which I wish to use, however it has somehow created stdClass variables which have numeric only names and thus are unaddressable by PHP as far as I can tell.

Here's a snippet from a print_r() of the object

Code: Select all

 
            [highlighting] => stdClass Object
                (
                    [000012192] => stdClass Object
                        (
                            [t_text] => Array
                                (
                                    [0] => 
                [advert]
                PRIORY PRESS LIMITED
THE FRIARY - <em>CARDIFF</em>
 
TELEPHONE 3578
              
                                )
 
                        )
 
                    [000012193] => stdClass Object
                        (
                            [t_text] => Array
                                (
                                    [0] =>  Religion.
Low Performing Fees
THE BOOK - 1/6
From the Publishers?
PRIORY PRESS LIMITED
The Friary - <em>Cardiff</em>
              
                                )
 
                        )
 
if I try this

Code: Select all

 
echo $this->results->highlighting->000012192->t_text[0];
 
I get this error

Code: Select all

 
[Wed Mar 11 11:32:57 2009] [error] [client xx.xx.xx.xx] PHP Parse error:  syntax error, unexpected T_LNUMBER, expecting T_STRING or T_VARIABLE or '{' or '$' in /var/www/ccymod/application/views/scripts/browse/search.phtml on line 62
 
I'm stumped. Any ideas?

Re: How to address a numericly named object member variable

Posted: Wed Mar 11, 2009 6:46 am
by VladSun

Code: Select all

echo $this->results->highlighting->{'000012192'}->t_text[0];

Re: How to address a numericly named object member variable

Posted: Wed Mar 11, 2009 6:52 am
by Surfr
VladSun I owe you a $drink

Many thanks. I'd never seen that notation for vars before. Problem solved :D