|
Posted by Jason Barnett on 01/07/05 01:39
Jay Blanchard wrote:
> Good afternoon gurus and gurettes,
>
> If I have a large app what is the difference, other than having a very
> large file, of doing this
>
> switch($action){
> /* several dozen cases to follow */
> case "foo":
> writing out all of the code
> break;
> }
>
> and this
>
> switch($action){
> /* several dozen cases to follow */
> case "foo":
> include that will handle processing this case
> break;
> }
>
> Correct me if I am wrong, but includes (and/or requires) will get all of
> the code in all of the cases regardless if the case is being processed.
> That being the case the code would essentially be the same length. Given
> that, would there be an efficieny issue?
I thought there was a difference for include and require for
conditionals. But apparently not. :)
In any case doing the switch makes a difference as to which files will
actually be parsed at runtime and the following code should illustrate
(assuming you have class definitions in the files you want to include).
<?php
$php_classes = get_declared_classes();
$condition = 'test';
switch ($condition) {
case 'test':
include_once 'echo.php';
break;
case 'required':
require_once 'common.php';
break;
default:
echo 'Nothing was included!';
break;
}
/** Now you can print the user defined classes to see if the code was
included or not. */
print_r(array_diff(get_declared_classes(), $php_classes));
?>
--
Teach a person to fish...
Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
PHP Manual: http://php.net/manual/
php-general archives: http://marc.theaimsgroup.com/?l=php-general&w=2
Navigation:
[Reply to this message]
|