Page 1 of 1
On which moment PHP executes an include on a switch?
Posted: Tue Mar 31, 2009 10:41 am
by lovelf
Code: Select all
<?php switch(browser_detection(browser)) {
case "msie6":
include_once("hvarie6.php");
break;
case "mozilla":
$fie6a= "";
$fie6b= "";
$fie6c= "";
$fie6d= "";
$fie6e= "";
$fie6f= "";
$fie6g= "";
?>
I would like to know if the php include occurs only for case msie6 or if the file is included anyway, the code above is just an example, I use many includes on switch statements and I am curious whether PHP actually includes the file for any case regardless of the call being placed for a certain case on the switch.
Thanks
Re: On which moment PHP executes an include on a switch?
Posted: Tue Mar 31, 2009 11:33 am
by Mark Baker
One solution would be to test it and see; but I'll save you the effort.
PHP only includes the file when the case condition matches
Re: On which moment PHP executes an include on a switch?
Posted: Wed Apr 01, 2009 1:20 am
by lovelf
But how could I test it?
The file might be included anyway from the server and not used for a certain case.
Thanks.
Re: On which moment PHP executes an include on a switch?
Posted: Wed Apr 01, 2009 1:27 am
by Benjamin
lovelf wrote:But how could I test it?
The file might be included anyway from the server and not used for a certain case.
Thanks.
Use require()
Re: On which moment PHP executes an include on a switch?
Posted: Wed Apr 01, 2009 2:42 am
by Mark Baker
lovelf wrote:But how could I test it?.
A.php
B.php
C.php
Main.php
Code: Select all
$test = 'B';
switch ($test) {
case 'A':
include('A.php');
break;
case 'B':
include('B.php');
break;
case 'C':
include('C.php');
break;
}
Re: On which moment PHP executes an include on a switch?
Posted: Mon Apr 13, 2009 1:03 am
by lovelf
Thanks Mark, I got it now.