Jump to content

objects with numbers as name!?


chiprivers

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/52860-objects-with-numbers-as-name/
Share on other sites

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);

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.