Efficiency of PHP arrays cast as objects?

Posted by keithjgrant on Stack Overflow See other posts from Stack Overflow or by keithjgrant
Published on 2011-01-07T17:38:27Z Indexed on 2011/01/07 17:53 UTC
Read the original article Hit count: 231

Filed under:
|
|
|

From what I understand, PHP objects are generally much faster than arrays. How is that efficiency affected if I'm typecasting to define stdClass objects on the fly:

$var = (object)array('one' => 1, 'two' => 2);

If the code doing this is deeply-nested, will I be better off explicitly defining $var as an objects instead:

$var = new stdClass();
$var->one = 1;
$var->two = 2;

Is the difference negligible since I'll then be accessing $var as an object from there on, either way?

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays