Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 02-09-2010, 08:54 AM A simple framework
Experienced Talker

Posts: 41
Name: Adam B
Trades: 0
Hi everyone. My first post here.

I'm just in the process of creating my first, very simple custom framework. All I basically want is a selection of helper objects that will make coding on some future projects a lot quicker.

It all works fine at the moment, however I'm just wondering what would be the best method of including the files, for my situation? At the moment I have a series of require_once statements at the top of each file. This wasn't really a problem at first, but as the project grows it's getting a little annoying having to have this big block at the top of each file.

I considered a kind of "master" file that I could include, that would include all my objects, but this would add uneccesary overhead on those I don't use.

What would your suggestions be?

Thanks

Adam
adam89 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-09-2010, 09:11 AM Re: A simple framework
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Have one file with all the "requires" defined and include that file.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-09-2010, 09:22 AM Re: A simple framework
Experienced Talker

Posts: 41
Name: Adam B
Trades: 0
Quote:
Originally Posted by adam89 View Post
I considered a kind of "master" file that I could include, that would include all my objects, but this would add uneccesary overhead on those I don't use.
Not quite what I'm after.
adam89 is offline
Reply With Quote
View Public Profile
 
Old 02-09-2010, 09:28 AM Re: A simple framework
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
How would it add "unnecessary overhead"?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-09-2010, 09:35 AM Re: A simple framework
Experienced Talker

Posts: 41
Name: Adam B
Trades: 0
...Because it's including redundant code? Say I have 20 of these object files and only use 2 on a particular page.. Whilst obviously it's never likely to impact the server's performance I'd rather take a more 'programmed' approach. Perhaps implementing a simple object factory or use of the __autoload function.

Curious to see how others would do this.
adam89 is offline
Reply With Quote
View Public Profile
 
Old 02-09-2010, 10:10 AM Re: A simple framework
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You are misunderstanding how interpreted code (PHP, ASP, Perl) actually works. IF it was compiled code such as ASP.net then it can affect the "footprint" of the application.

Including all the references to code and classes does not impact on the resources used, it does not impact on the script load times. Even in ASP where the interpreter does TWO passes through the included pages there is absolutely no increase in script times (or if there is it is in microseconds).

For www.modtalk.co.uk the global include file (in every page) calls in 120 different includes and class definitions, it also instantiates 60+ objects (yep OOP in VbScript)
The objects are destroyed as the script ends.

With PHP, ASP etc the page is called, served then destroyed, loading "redundant code" does nothing at all. If the functions, classes, methods are needed they get called, if they are not needed they are simply ignored.
Just as long as you use correct practice and close and destroy any objects that have been instantiated there will be no "ill effects" whatsoever.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-09-2010, 10:50 AM Re: A simple framework
Experienced Talker

Posts: 41
Name: Adam B
Trades: 0
You're misunderstanding the definition of "redundant".

Quote:
Originally Posted by adam89 View Post
Whilst obviously it's never likely to impact the server's performance I'd rather take a more 'programmed' approach.
I am aware the code will not be run, and I'm aware it would have virtually no impact on the server (perhaps a few microseconds as you say). What I am saying is, and however trivial you think I'm being, I don't see the point in having to maintain a long list of includes (and redundant code) when I could dynamically include the file and instantsiate the object in one go, only as and when I need it.

I'm looking for a cleaner, more systematic approach to this.

Last edited by adam89; 02-09-2010 at 10:51 AM..
adam89 is offline
Reply With Quote
View Public Profile
 
Old 02-09-2010, 11:23 AM Re: A simple framework
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I'm looking for a cleaner, more systematic approach to this.
And that would be carry on doing what you do now, which is what you wanted to avoid in the first instance.

Either that are you make it far more complicated by having "modules" of includes, over several years and many web applications I find a single list of all the includes if far more organised than having to edit many pages just to add a group of functions to them.

I am firmly in the "write once" "use many" school of programming and just about every aspect of a page will be a class method or a function, so I probably have less redundant code than most.

Redundant code is NOT code that you have available but do not call, redundant code is having the same piece of code written several time.

For example the DTD is only defined once in the entire site (actually all DTDs are defined in a class module and called via a method, just so I can change the standard DTD globally, or for a single page should I so wish.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-09-2010, 11:39 AM Re: A simple framework
Experienced Talker

Posts: 41
Name: Adam B
Trades: 0
Can't see us agreeing here any time soon.

However (from http://en.wikipedia.org/wiki/Redundant_code ):
Quote:
The term redundant code may also be used to described code that has any form of redundancy, such as recomputing a value that has previously been calculated and is still available, code that is never executed, or a result which is executed and not used.

Last edited by adam89; 02-09-2010 at 11:40 AM..
adam89 is offline
Reply With Quote
View Public Profile
 
Old 02-11-2010, 05:23 PM Re: A simple framework
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
Adam, PHP allows you to autoload classes so that you don't have to have a file with a lot of includes. If you have a consistent naming pattern and file structure, it's actually quite easy.
__________________
Want new web resources every day? - Follow me on
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 02-12-2010, 07:24 AM Re: A simple framework
Experienced Talker

Posts: 41
Name: Adam B
Trades: 0
Yeah I've looked into these.. Looking like the best option. Just curious really if anyone has any other/unique methods they use to implement such a thing?
adam89 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to A simple framework
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.66900 seconds with 12 queries