I have been using arrays to store related fields during a long time. If I wanted to have related user fields, I used:
$user = array(
'id' => 27
'name' => 'Pepe'
);
But lately, I've been working a lot with objects, and I like it more to use $user->id instead of $user['id'].
My question: To achieve an object oriented style, you may use stdClass:
$user = new stdClass();
$user->id = 27;
$user->name = 'Pepe';
or casting from an array
$user = (object) array(
'id' => 27
, 'name' => 'Pepe'
);
Is one of them better than the other, in order of performance and style, or can you use whatever you want indistinctly?
Based on small test I can say that using "new stdClass()" is about 3 times slower than other options.
It is strange, but casting an array is done very efficiently compared to stdClass.
But this test meters only execution time. It does not meter memory.