I have a variable like
$a = array(
'first' => array( 'b' => 2, 'c' => 3),
'second' => array('d' => 4, 'e' => 5)
);
To access an element, I can use
$a['first']['c']
But to access it like this,
$a->first->c
I can cast the array into object as follows:
$a = (object)array(
'first' => (object)array( 'b' => 2, 'c' => 3),
'second' => (object)array('d' => 4, 'e' => 5)
);
But i have to use the same inside a class like this..
class className {
public static $a = (object)array(
'first' => (object)array( 'b' => 2, 'c' => 3),
'second' => (object)array('d' => 4, 'e' => 5)
);
}
It throws a T_OBJECT_CAST error. How can i make it work, if i want to access the element like
className::$a->first->c;