RE: On large application organization [long and possibly boring]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[snip]
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.
[/snip]

This doesn't prove the case either way.  It would be similar to writing
this code:
<?php
$include = 0;

if($include){
  function hello() {
	  print "Hello";
  }	
}
hello();

?>

Which also throws an error.  We looked a while and found nothing
in the documentation, so we ended up putting an error in the include
file.  
foo.php

<?

$include = "b";

switch ($include){
 case "a":
   include("foo2.php");
 break;
 case "b":
   echo "bar";
 break;
}

?>

foo2.php
<?
//note syntax error
echo "foo"
?>

Assumably, if includes were processed before the script was 
executed, it would show a syntax error in foo2.php.  We ran
the test and no error was returned, so that pretty much answers
the question (READ: includes are not processed until they
are called).  
Just out of curiosity, a lot of people had answers to this
question, but I couldn't find a shred of evidence in the 
documentation.  Did you do similar tests, hear from gurus, or
something of like?  Or did I just miss it somewhere?

Regards,
Jesse R. Castro

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux