Search notes:

PHP: require_once

require_once() is like require() but includes the file at most once. That is, the second time a file is tried to be included with require_once(), it has no effect.
The files to be included are searched in the include path (whose current value is returned by get_include_path()).
If require_once() does not find the file to be included, it raises E_COMPILE_ERROR which cannot be caught in a try … catch construct. Therefore, one might consider using include_ince() instead.
<!-- http://www.adp-gmbh.ch/php/include_require.html -->
<html>
<head><title>require_once</title></head>
<body>

<?php

 // http://stackoverflow.com/a/2418744/180275
    require_once('required_file.php');

    $num_1 = 10;
    $num_2 = 20;

    print "The average of $num_1 and $num_2 is " . avg($num_1, $num_2);

?>

</body>
Github repository about-php, path: /including-files/require_once.html

required_file

This is the file that is required by required_once.
<pre>
  If the included or required file contains php code, the code must be between
  &lt;?php ... &gt; even though the include/require command is already contained
  within &lt;?php ... &gt;.
  
  Text that is not within those tags will be sent to the browser!
</pre>
<?php

   function avg($a, $b) {
      return ($a+$b)/2;
   }

?>
Github repository about-php, path: /including-files/required_file.php

See also

Including files.
Other PHP snippets

Index