Page 1 of 1

solved: include() inside functions and if statements

Posted: Sat Oct 28, 2006 12:53 pm
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

Posted: Sat Oct 28, 2006 12:55 pm
by nickvd
If you don't call the function, then whatever is inside wont get executed (or included), same goes with an if statement.

Posted: Sat Oct 28, 2006 1:01 pm
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?

Posted: Sat Oct 28, 2006 7:16 pm
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.

Posted: Sat Oct 28, 2006 11:37 pm
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.

Posted: Sat Oct 28, 2006 11:47 pm
by John Cartwright
wyrmmage wrote:ok, I'll try that :) where can I find Xdebug?
Google :roll:

Posted: Sun Oct 29, 2006 12:07 am
by wyrmmage
lol, ok, ok, I can take a hint :P Anyway, thanks for the help :)

-wyrmmage

Posted: Sun Oct 29, 2006 3:02 am
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? ;)

Posted: Sun Oct 29, 2006 10:37 am
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)