Karel Kozlik schrieb: > Hi, > I am just thinking about that what is better for storeing structured > variables in point of view of performance. > > Is better store structured variables in associative array, for example: > > $person['first_name'] = 'Karel'; > $person['last_name'] = 'Kozlik'; > $person['address'] = 'somewhere on Earth'; > > or in object like this: > > $person->first_name = 'Karel'; > $person->last_name = 'Kozlik'; > $person->address = 'somewhere on Earth'; > > I feel that objects are better for performance, but work with > associative arrays is pleasanter for me. May be the diference in > performance measurable? (in heavy loaded environment) First of all: You are already using something like eAccelerator? You have optimized your database queries to take full advantage of the query cache in your DBMS? You are using a userland cache to increase the performance for seldomly changing content? If the question is "No" to these or similar questions: Don't waste your time on thinking about performance differences in the microsecond range! Unless your site really has to take some hundred thousand page requests a day this is just silly. Now for the concept of array vs. attributes: I used to prefer the array notation, too. But think about this: Arrays suggest some similarity between the array elements, it suggest the elements are somewhat of the same type. On the other side attributes are just that: Attributes of an entity. So, it's more appropriate to use array notation for a collections of persons but not for the attributes of a single person. This started to change my mind about using array syntax here. Besides, using -> saves you two keystrokes/bytes. OK, that was for conceptual view. Now technical ;-) The performance depends on the version of PHP you are using. For PHP4, classes and objects are very much like arrays in disguise, it's only with the Zend Engine 2 of PHP5 that this has changed. This engine has greatly improved performance in PHP 5.1, so yeah, with PHP5.1 attributes could be quicker than arrays BUT you shouldn't care ;-) But remember: Always prefer concept to performance when designing software. Performance considerations are welcome and important for the large scale (as in "you shouldn't fetch all the rows in a table if you display only ten of them => use LIMIT") but micro-profiling is definitely something you should do when the system's up and running. OLLi -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php