Industrial Industrial - 2 months ago 26
PHP Question

Is it bad for performance to extract variables from an array?

I have found out about the great

function in PHP and I think that it is really handy. However I have learn that most things that are nice in PHP also affects performance, so my question is which affect using the
can have, seen in a performance perspective?

Is it a no-no to use for big applications to extract variables outta arrays?



As the commenter below noted and as I am now keenly aware years later - php variables are copy on write. Extracting in the global scope will however keep the variables from being garbage collected. So as I said before, "consider your scope"

Depends on the size of the array and the scope to which your extracting it, say you extract a huge array to the global namespace, I could see that having an effect, as you will have all that data in memory twice - I believe though it may do some fun internal stuff which PHP is known to do to limit that -

but say you did

function bob(){
    extract( array( 'a' => 'woo', 'b' =>'fun', 'c' => 'array' ) );

its going to have no real lasting effect.

Long story short, just consider what you're doing, why your doing it, and the scope.