Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: 'include' and 'require_once'  (Read 2317 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.

TIA
Logged

Mika

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

From php.net 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
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version