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
PHP includes question
Old 07-07-2008, 06:31 AM PHP includes question
drew22299's Avatar
Skilled Talker

Posts: 93
Trades: 0
Hi,

I have a php file that consists of two include files and I want to include it within another php file called main_page.php. Is there a limit to how many includes of php files you can have?

For example, would this be possible?

main_page.php
contains: include (page1.php)

page1.php
contains: include (page2.php)

page2.php
contains: include (page3.php)

page3.php (no includes)

Thanks,
drew22299 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-07-2008, 07:33 PM Re: PHP includes question
Defies a Status

Posts: 1,606
Trades: 0
Other than a minor risk of server over-load I can think of no reason why you should not do it.


If the same file is called once you should restructure or or include_once.
__________________
Colbyt

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

Last edited by colbyt; 07-07-2008 at 07:33 PM.. Reason: typo
colbyt is offline
Reply With Quote
View Public Profile
 
Old 07-08-2008, 12:59 AM Re: PHP includes question
Extreme Talker

Posts: 238
Location: United States
Trades: 0
It's not a problem from a technical point of view, but I sometimes find it an issue as a developer, especially when I'm trying to make sense of what others have done on a project before me.
__________________
The interlocking pieces of web development: usability, performance, accessibility, and standards.
frost is offline
Reply With Quote
View Public Profile
 
Old 07-08-2008, 07:52 AM Re: PHP includes question
drew22299's Avatar
Skilled Talker

Posts: 93
Trades: 0
colbyt, is that the same as require_once? I thought it had to be loaded every time the page is refreshed?

frost, that's a good point, I think I will have to provide some comments to explain the different includes

Thanks,
drew22299 is offline
Reply With Quote
View Public Profile
 
Old 07-08-2008, 09:34 AM Re: PHP includes question
drew22299's Avatar
Skilled Talker

Posts: 93
Trades: 0
I have just tried to include the file (which has many includes) in a main page and now there are alot of errors similar to this one:

PHP Code:
Call to a member function on a non-object in /folder/html/organisation_info.inc on line 200 
Which point to MySQL queries which should work, such as

Quote:
$orgTypes =& $db->query("SELECT * FROM organisation WHERE organisationId = '$_GET[id]'");
checkDBError($orgTypes);
I realise this is a specific problem but why would the code work previously (before I included it within another file) and not work now?

Thanks,

Last edited by drew22299; 07-08-2008 at 09:35 AM..
drew22299 is offline
Reply With Quote
View Public Profile
 
Old 07-08-2008, 03:04 PM Re: PHP includes question
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Because this line use an Object.
The object has to be declared before, and it's obviously done in 1 of the include, so the part
PHP Code:
$orgTypes =& $db->query("..."); 
Which probably will send a query to the db (the & means that's the variable are passed by reference, rather than copy [ http://www.php.net/manual/en/languag...ences.pass.php ] )

This means that somewhere (over the rainbow ;-P ) in your includes, a new object is initialized, and used in that include.
Pretty messy, if you want my opinion...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-09-2008, 10:32 AM Re: PHP includes question
drew22299's Avatar
Skilled Talker

Posts: 93
Trades: 0
Yeah it was definatly in the includes and it was abit messy so I decided to keep the code separate
drew22299 is offline
Reply With Quote
View Public Profile
 
Old 07-12-2008, 10:25 PM Re: PHP includes question
Junior Talker

Posts: 2
Trades: 0
I guess we can have as many includes in a script. When you use include more than once for the same file, you may get an error. Instead use include_once.

But the best way to do it is to use the PHP "magic" function, __autoload.
Read this page for more info.

http://us2.php.net/manual/en/language.oop5.autoload.php
anabayan is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP includes question
 

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.27479 seconds with 12 queries