You are here: Re: [PHP] On large application organization [long and possibly boring] « PHP « IT news, forums, messages
Re: [PHP] On large application organization [long and possibly boring]

Posted by Jamie Alessio on 01/07/05 01:56

>> 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.
>>
You're wrong. The include() and require() statements are only evaluated when they are reached in your application code, so there is a big difference between your two examples. In you use the second example the code will only be included by PHP if the application logic enters the case statement that contains the include() statement. Here's a quick example to demonstrate this:

////////////
// 1.php
///////////
<?php
$include = 0;

if($include)
include('2.php');

hello();

?>

////////////
// 2.php
///////////
<?
function hello() {
print "Hello";
}
?>

Save those two snippets into files named 1.php and 2.php. Pull up 1.php in your browser and you'll see that the hello() function is undefined.

- Jamie

>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?
>
>This would (the second way) also make the project easier to work on by
>multiple programmers at the same time, similar to modular work being
>done by programmers on C++ projects.
>
>One of the reasons for doing this is so that global includes and certain
>class definitions, such as an error checking function relavent to most
>cases, can be included once.
>
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация