这取决于您使用的 php 版本。如果您使用的版本是 PHP5 或更高版本(您应该作为最新的 php 版本将意味着您的游戏应用程序的性能更高),那么同时使用数组和对象将为您的应用程序提供几乎相同的性能。因此,如果您正在使用/可以使用 PHP 5 或更高版本,那么您可以根据自己的方便使用数组或对象。
检查此数组与 Aron Novak 的对象比较/测试:http ://aggregation.novaak.net/?q=node/227 。我在下面用 Aron Novaks 的话引用它:
I created a small script to find out which data structure has better performance. You can find the script what I used for the test at the attachments.
My test results are:
data structure PHP4 PHP5
object 61.6224 37.576
array 57.6644 37.866
The results are in milliseconds(ms). It seems that in PHP5 the data structure is totally indifferent, in PHP4 there is approximately 7% performance gain if use arrays instead of objects.
"This revolution, however, left PHP's object model mostly unchanged from version 3 – it was still very simple. Objects were still very much syntactic sugar for associative arrays, and didn't offer users too many features on top of that." (http://devzone.zend.com/node/view/id/1717)
So the syntactic sugar is not a bad thing at all :) And it costs almost nothing. This is an explanation why all the parsers' output uses objects.
检查此http://we-love-php.blogspot.com/2012/06/php-memory-consumption-with-arrays.html以获取有关PHP 数组与对象内存使用和性能的详细/精彩文章