Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In both cases you need to create a instance of a class (stdClass or Array) and set the data. In the second case you add a new operation, the cast, therefore exists implicit the creation of an stdClass instance and the parsing data operation from Array to stdClass.</p> <p>In first case, you only create a instance of a class, in the second are create both, but 1 is invisible to the programmer. I think that the first is more efficient in memory and speed</p> <pre><code> 1 &lt;?php 2 3 $time_start = microtime(true); 4 5 for($i=0 ; $i&lt;1000000; $i++) 6 { 7 $profile = new stdClass;$ 8 $profile-&gt;first_name = 'Woppi'; 9 $profile-&gt;last_name = 'Jillenjack'; 10 $profile-&gt;email = 'woppi.jillenjack@gmail.com'; 11 $time_end = microtime(true);$ 12 } 13 14 $object = $time_end - $time_start; 15 16 17 $time_start = microtime(true); 18 for($i=0;$i&lt;1000000;$i++) 19 { 20 $profile = array('first_name'=&gt;'Woppi', 21 'last_name'=&gt;'Jillenjack', 22 'email'=&gt;'woppi.jillenjack@gmail.com'); 23 $profile = (object)$profile; 24 $time_end = microtime(true); 25 } 26 $array_to_object = $time_end - $time_start; 27 28 echo "stdClass: $object | Typecasting: $array_to_object"; 29 30 ?&gt; </code></pre> <p>stdClass: 10.045720100403 | Typecasting: 10.009358882904</p> <p>stdClass: 9.9519069194794 | Typecasting: 9.2100629806519</p> <p>stdClass: 9.2515120506287 | Typecasting: 9.480808019638</p> <p>stdClass: 9.5376181602478 | Typecasting: 9.2310011386871</p> <p>stdClass: 9.9628109931946 | Typecasting: 10.414475917816</p> <p>The test is not conclusive, in this case maybe the memory consumed help us to make a choice for use one or other </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload