What I am trying to do is to dynamically create an array property to an object by passing its string to a function.
I'll give a better example, that's what I need to do:
$property = 'string_array';
$object->$property[1] = 'Something';
echo $object->string_array[1];
That should print 'Something' but it doesn't.
A working option would be to do:
$property = 'string_array';
$object->$property = array(1 => 'Something');
echo $object->string_array[1];
That code works, but it overwrites the $object->string_array which I don't want to happen. I just want a new member added to it.
The only solution I found so far is to write it like that:
$object->$property = array();
$object->$property += array(1 => 'Something');
$object->$property += array(2 => 'Something else');
echo $object->string_array[1];
And that's really what I am trying to do - Add a new item to an existing array which I access my name.
Do you have a better solution to this?