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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758204577, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/web/php/snippets/require_once(90): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78