05-05-2009, 05:33 AM
|
#1 (permalink)
|
|
The Contributor
Join Date: Feb 2007
Posts: 64
Thanks: 9
|
Array and object performance
I decided it was time to continue working on my CMS again and am working on finishing up what was missing, and re-working a few tasks.
I have a component layer, which basically handles all the content tasks. Think Joomla for a second, if your familiar with it. Basically, I check if any component is set, and require its file if so. If the component has auto_start defined as true, and it is a class, the CMS will automatically call it.
It used to pass about 6 objects to the constructor, the database abs, config, core functions obj, user obj, xml parser / cacher, and plugin object.
I do this to prevent the need to global vars, but I dont like so many vars passed. So, I decided to trim this down.
Before calling the component file, I packaged all vars into an array...
$system['database'] = $database;
$system['config'] = $config;
etc etc etc
Now I just pass this array to the constructor so its one var to deal with instead of setting and passing 6 or 7.
Now my question, is wrapping an object into an array going to really hurt performance? So far, the CMS is fairly large scale, but runs extremely fast. Very few queries are executed.. infact, before the plugin layer, no queries were executed if there was a cached page to load ( cache also has option to make CMS work as flat file, stored as XML docs ).
I want to keep the CMS running fast, and I didnt think an array with 6 or 7 keys would do much to performance, but wasnt sure. I als wasnt sure if writing ...
if($system['user']->id > 0) { ... }
if(!$system['database']->query($query)) { ... }
Anyone have any input on which direction would be the better choice?
|
|
|
|