1

Is it possible to access to object member as if array member?

for example

echo $a->b;

to

echo $a[b];

Would it be any php ini settings, or this is quite impossible in PHP?

Samuel
  • 21
  • 6

2 Answers2

2

extends ArrayObject or implements ArrayAccess so you can access the object as array.

Reading Material

ArrayObject

ArrayAccess

Script47
  • 14,230
  • 4
  • 45
  • 66
2

I tried for a one-liner but:

$x = (array)$a;
echo $x['b'];

Or of course to convert the object: $a = (array)$a;

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87