chiprivers Posted May 24, 2007 Share Posted May 24, 2007 I have an object of which the structure is like this: Array ( [0] => stdClass Object ( [asianLineId] => 0 [bestPricesToBack] => stdClass Object ( [Price] => Array ( [0] => stdClass Object ( [amountAvailable] => 391.52 [betType] => L [depth] => 1 [price] => 6.4 ) etc etc I want to reference the [amountAvailable] value, shown above as 391.52. I am new to OOP and for non numeric names I would use this: $marketPrices->0->bestPricesToBack->Price->0->amountAvailable but this does not work and I think it is because of the 0's (zero). I get the following fault: Parse error: syntax error, unexpected T_LNUMBER, expecting T_STRING or T_VARIABLE or '{' or '$' in C:\xampp\htdocs\BFAuto\selectionLayer.php on line 45 Any suggestions how I can get around this? Quote Link to comment https://forums.phpfreaks.com/topic/52860-objects-with-numbers-as-name/ Share on other sites More sharing options...
448191 Posted May 24, 2007 Share Posted May 24, 2007 This should work: $marketPrices[0]->bestPricesToBack->Price[0]->amountAvailable; There is something odd about that print_r too. How come the objects are of type stdClass? What are you doing? Please use this code (replace $obj with your object), and show us the results: $refl = new ReflectionObject($obj); Reflection::export($refl); Quote Link to comment https://forums.phpfreaks.com/topic/52860-objects-with-numbers-as-name/#findComment-260988 Share on other sites More sharing options...
chiprivers Posted May 24, 2007 Author Share Posted May 24, 2007 Hi, thanks for the response, I was just coming back to put a post saying I had worked it out! I did that thing you wanted and now I get this error: Warning: ReflectionObject::__construct() expects parameter 1 to be object, array given in C:\xampp\htdocs\BFAuto\selectionLayer.php on line 65 Fatal error: Internal error: Failed to retrieve the reflection object in C:\xampp\htdocs\BFAuto\selectionLayer.php on line 66 I am working on a script that exchanges data through the Betfair API service for horse racing bets. This is one of the objects returned for a call I have made, however I understand that it is a combination of objects and arrays! Quote Link to comment https://forums.phpfreaks.com/topic/52860-objects-with-numbers-as-name/#findComment-260999 Share on other sites More sharing options...
448191 Posted May 24, 2007 Share Posted May 24, 2007 Reflection no worky on arrays. Stupid me. Quote Link to comment https://forums.phpfreaks.com/topic/52860-objects-with-numbers-as-name/#findComment-261013 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.