StdClass vs array. What is recommended?

Where is it recommended to use one of them? I want to store data from articles listed in db.

This is a simple question:

echo $Datastore->name; //I like it works with foreach

//vs

echo $Datastore['name'];

What's better? Is there a difference between stdClassand the arrayspeed at which items are received?

+4
source share
1 answer

There is a similar question. What is better for the stdClass array or (object) for storing related data? with this answer

Based on a small test ( http://phpfiddle.org/lite/code/cz0-hyf ), I can say that using the "new stdClass ()" is about 3 times slower than the other options.

, stdClass.

. .

P.S. phpFiddle . PC.

:

  • PHP 5.5 PHP 5.4,
  • , , PHP 5.5 .
  • stdClass .
  • - , . ( 30-40% !!).
  • SplFixedArray , .
+8

Source: https://habr.com/ru/post/1546822/


All Articles