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

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

 



>> This doesn't prove the case either way.
>>
Nice catch on that one but actually there might be another problem with my example. According to example 16-8 on http://us2.php.net/include/ "Because include() and require() are special language constructs, you must enclose them within a statement block if it's inside a conditional block". So, I think I would need to rewrite


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

to be

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

in order for it "to work as desired". I'm not exactly sure what it means to "work as desired" though. Maybe it only applies if you have additional else/elseif statements in the block?

BUT, also from documentation on http://us2.php.net/include/ it looks like your example might not hold any water either. "Be warned that parse error in required file doesn't cause processing halting." Based on that it appears that introducing the parse error in foo2.php doesn't prove that the file wasn't included. So, how do we actually prove this one way or the other? I guess we could just like at the underlying C code. Any takers?

- Jamie

[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