Please login or register.

Login with username, password and session length
Advanced search  


You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: 'include' and 'require_once'  (Read 2372 times)

Manuel Pancorbo

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 72
'include' and 'require_once'
« on: November 29, 2006, 04:13:42 pm »

I'm not an expert php-programmer, so perhaps my question is trivial.

There is an initial load of "snews.php" at the begining of the start-up file "index.php". Is there any difference if I reference the file by the command "require_once(snews.php)" instead of "include(snews.php)"? I feel the first lighter and quicker than the second.



  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
'include' and 'require_once'
« Reply #1 on: December 01, 2006, 09:35:17 am »

From manual:
require() and include() are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error.

include_once()/require_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc.

All the processes are done inside (included) snews.php file, and the index.php has the sole purpose to display the resulting data according to inserted routines some_function ?>. In this case you're free to use whichever construct (with or without  "_once") you prefer.
Logged - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version