TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-05-2009, 05:33 AM   #1 (permalink)
The Contributor
 
Join Date: Feb 2007
Posts: 64
Thanks: 9
Killswitch is on a distinguished road
Default 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?
Killswitch is offline  
Reply With Quote
Old 05-16-2009, 09:50 PM   #2 (permalink)
The Wanderer
 
gregor171's Avatar
 
Join Date: May 2009
Location: Ljubljana, Slovenia
Posts: 9
Thanks: 0
gregor171 is on a distinguished road
Default

The answer would be NO if...

Since mentioning Objects. A good idea about how to do this OOP way is by using Object patterns:
http://en.wikipedia.org/wiki/Design_...puter_science)
http://www.ibm.com/developerworks/li...AGX01&S_CMP=LP
http://www.ibm.com/developerworks/op...GX44&S_CMP=EDU

I read a good PHP based book about this topic
PHP Objects, Patterns, and Practice by Matt Zandstra (Apress, 2008)

This might give you some ideas, how to solve this. I know. I have the same problem every time. If I study to much about one problem, new problems will arise and I'll have to study even more.

By making a good architecture you might lose some performance, but you'll gain more elsewhere.
__________________
WEB Developer
http://xweblabs.com
http://grajzar.info
Send a message via Skype™ to gregor171
gregor171 is offline  
Reply With Quote
Old 05-17-2009, 10:02 AM   #3 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

This sounds like a problem which could be easily solved using the registry pattern. Consider documenting about that, it will definitely improve your code
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 05-20-2009, 10:38 AM   #4 (permalink)
The Wanderer
 
Join Date: Nov 2007
Location: Mumbai, India
Posts: 24
Thanks: 0
sunilbhatia79 is on a distinguished road
Default

Hi,

I advice using global variables.

I know many will have raised eyebrows - but that is the best thing to do.

With Global variables you will have a tradeoff with memory - but since your list is small - I think it should be fine.

You should create an associative array for Global Variables so that you can load its value through the key. This will also ensure that you don't get mixed up with index numbers.

Regards,
Suniil
__________________
Sunil Bhatia www.twitter.com/sunilbhatia79 - Follow me on Twitter
PHP5 Tutorials
Career Articles
sunilbhatia79 is offline  
Reply With Quote
Old 05-20-2009, 01:01 PM   #5 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

What about using a Dependency Injection Container, good tutorial on DI and containers:
http://fabien.potencier.org/article/...ency-injection
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Easily Format JSON using PHP and Interpret using Javascript Wildhoney Advanced PHP Programming 13 02-01-2013 11:05 AM
Dingo Framework - ALPHA Testing Open! ETbyrne Show Off 97 10-18-2012 02:11 PM
Help search through file.... allworknoplay Absolute Beginners 10 03-22-2009 02:15 AM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
array to object Gibou Advanced PHP Programming 11 03-24-2008 06:07 PM


All times are GMT. The time now is 08:16 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design