René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

include/require [php]

If the included or required file contains php code, the code must be between <?php ... > even though the include/require command is already contained within <?php ... >.
some_file.inc
<?php

function h2($h) {
  print "<h2>$h</h2>";
}

?>
<?php 

  require('some_file.inc'); 

  h2('foo');

?>

Variables

other_file.inc
<?php

print "<br>inc: var: $var, var_global: $var_global";

$var        = 'include';
$var_global = 'include';

<?php 

  global $var_global;

  $var        = 'calling';
  $var_global = 'calling';

  print "<br>cal: var: $var, var_global: $var_global";

  include('other_file.inc'); 

  print "<br>cal: var: $var, var_global: $var_global";
?>
This results in:

cal: var: calling, var_global: calling
inc: var: calling, var_global: calling
cal: var: include, var_global: include
As can be seen, the global statement makes no difference.