I have a type variable
$a = array(
'first' => array( 'b' => 2, 'c' => 3),
'second' => array('d' => 4, 'e' => 5)
);
To access an item, I can use
$a['first']['c']
But to access this,
$a->first->c
I can convert the array to an 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 such a class.
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 an element of type
className::$a->first->c;
source
share