Reputation: 957
Im returning an array full of 3 objects to a function where i simply want to access the 3rd tier data.
Now when returned, i can var_dump the whole array and i can see it, i can also var_dump the array plus the number of the object i would like to use and see it. An example below:
I use this code:
$data = Container::make_orderList();
var_dump($data);
And i get this result:
array (size=3)
0 =>
object(order)[63]
private 'increment_id' => string '100000002' (length=9)
private 'created_date' => string '2013-10-19 19:34:02' (length=19)
private 'is_active' => null
private 'weight' => string '20.0000' (length=7)
private 'status' => string 'processing' (length=10)
1 =>
object(address)[55]
private 'company_name' => string 'No Company' (length=10)
private 'street' => string '20 Waterfall Way
Barwell' (length=25)
private 'city' => string 'Leicester' (length=9)
private 'region' => string 'Leicestershire' (length=14)
private 'postcode' => string 'LE9 8EH' (length=7)
2 =>
object(address)[54]
private 'company_name' => string 'CRanbri Web Solutions' (length=21)
private 'street' => string '4 Turner Drive
Hinckley' (length=23)
private 'city' => string 'Leciester' (length=9)
private 'region' => string 'LEicesterhsire' (length=14)
private 'postcode' => string 'LE10 0gu' (length=8)
private 'country_id' => string 'GB' (length=2)
and with:
$data = Container::make_orderList();
var_dump($data[0]);
I get this result:
object(order)[63]
private 'increment_id' => string '100000002' (length=9)
private 'created_date' => string '2013-10-19 19:34:02' (length=19)
private 'is_active' => null
private 'weight' => string '20.0000' (length=7)
private 'status' => string 'processing' (length=10)
private 'shipping_address_id' => string '4' (length=1)
private 'billing_address_id' => string '3' (length=1)
private 'shipping_method' => string 'flatrate_flatrate' (length=17)
private 'shipping_description' => string 'Flat Rate - Fixed' (length=17)
private 'order_id' => string '2' (length=1)
private 'gift_message' => null
This is great and what i need, but what im having trouble doing is accessing the individual fields of the array say for example the 'increment_id' field.
I have tried:
$data = Container::make_orderList();
var_dump($data[0]->increment_id);
But i get this error:
Fatal error: Cannot access private property order::$increment_id in C:\xampp\htdocs\magento_soap_client\fulfilment\soap\views\view.content.php on line 20
I don't suppose you could help me put with how i should access these fields?
Thanks
Upvotes: 0
Views: 136
Reputation: 5105
Just make the fields of your object public or create getters and/or setters for the fields. You might want to take a look at the documentation about visibility of properties and methods in PHP.
Upvotes: 2