I’m looking for the kind to access at the value of an array directly from the object’s method.
For example :
With this syntax, no problem :
$myArray = $myObject->getArray();
print_r($myArray[0])
But to reduce the number of line in source code, how to get the element directly with the method ?
I do that, but it’s not correct :
$myArray = $myObject->getArray()[0];
If you are on php 5.4 (which support array dereferencing) you can do the second option:
If you are on PHP < 5.4 you can “fix” it in the class (of which the object is a instance):