solved: include() inside functions and if statements

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wyrmmage
Forum Commoner
Posts: 56
Joined: Sat Oct 28, 2006 12:43 pm
Location: boise, ID

solved: include() inside functions and if statements

Post by wyrmmage »

If I have a function, like this:

Code: Select all

<?

function anIncludeFunction()
{

include 'whateverFile.php';

}

?>
that code was in a file called 'IncludeFunctionFile' , and then I have my main file like this:

Code: Select all

<?

include 'IncludeFunctionFile';

?>
Now, when the main file executes, it includes the IncludeFunctionFile.php but it doesn't call the anIncludeFunction()
So, my question is this: does 'whateverFile.php' still get included? What if I do the same thing with an if statement that never gets executed?

Thanks,
-wyrmmage
Last edited by wyrmmage on Sun Oct 29, 2006 12:08 am, edited 1 time in total.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

If you don't call the function, then whatever is inside wont get executed (or included), same goes with an if statement.
wyrmmage
Forum Commoner
Posts: 56
Joined: Sat Oct 28, 2006 12:43 pm
Location: boise, ID

Post by wyrmmage »

ok, thank you :) Most php tutorials make it seem like the file is included when the Zend engine parses the php file, no matter what. My entire site is based on include() and require() statements, since I am using a ?page variable, and my site has gotten to the point where it is so slow(even if only one user is accessing it), that it can not send all of the code to the client in under two minutes (on average) 8O

Anyway, thanks for the help....can anyone else confirm this please?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

can anyone else confirm this please?
he's right

Code: Select all

since I am using a ?page variable, and my site has gotten to the point where it is so slow(even if only one user is accessing it), that it can not send all of the code to the client in under two minutes (on average) Shocked
Something is definantly wrong here. PHP code execution is really fast, so I would venture to guess you have some type of bottleneck (such as a poor choice of loops). Take a look at Xdebug to track posible bottlenecks.
wyrmmage
Forum Commoner
Posts: 56
Joined: Sat Oct 28, 2006 12:43 pm
Location: boise, ID

Post by wyrmmage »

ok, I'll try that :) where can I find Xdebug?

Thanks,
-wyrmmage

P.S. my site is at game.ghettointeractions.com; if you create an account and then go to the 'play game' page, that is the page that is slow.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

wyrmmage wrote:ok, I'll try that :) where can I find Xdebug?
Google :roll:
wyrmmage
Forum Commoner
Posts: 56
Joined: Sat Oct 28, 2006 12:43 pm
Location: boise, ID

Post by wyrmmage »

lol, ok, ok, I can take a hint :P Anyway, thanks for the help :)

-wyrmmage
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

There something i don't understand: why would you want to include files that contain code that you're not going to use anyway? ;)
wyrmmage
Forum Commoner
Posts: 56
Joined: Sat Oct 28, 2006 12:43 pm
Location: boise, ID

Post by wyrmmage »

well.....perhaps I oversimplified my example. I am writing a text-game in php, therefore there are some functions that are called if the player has done something, and some that are called when the player does something else. For instance:
the player is attacking a monster, so he is in the battle screen. Therefore my code includes the battle screen code. If the player wins, a function is called, if the player loses, a different function is called, if the player niether wins or loses, he can continue to attack the monster until he does win or lose. Therefore there is the possibility of the winning function being called, the losing function being called, or neither one being called; I must include (at the very least) the function statement, even if the function only contains an include() statement to the code that was in the function.

Sorry if that didn't make any sense....if there is a better way of going about this, I would be greatful for some guidance 8)

-wyrmmage

Oh, and most of my code involves objects (although it wouldn't necessarily have to)
Post Reply