Which One Uses Less Memory in PHP? Objects or Arrays?
March 13, 2013 8:50 am Leave your thoughtsMany times this question pops in my mind and many others. Obviously if it’s more to do with representing objects such as a car or a person, then we use objects as it’s a more “proper” way of doing it. However if we just want to keep a set of data in a container represented by key – value representative, which one are we going to use?
So either:
1 2 3 4 5 |
class NavigationItem { public $text; public $href; public $icon; } |
OR
1 2 3 4 5 |
$navigationItem = array( "text" => "", "href" => "", "icon" => "" ); |
The answer is objects, in general uses less memory than array.
Head to the this great gist about what PHP do internally with objects.
https://gist.github.com/nikic/5015323
Tags: coding, performance tuning, phpCategorised in: PHP, Software Development