Search code examples
phprequirerequire-once

When is require ever preferred over require_once in PHP?


The way I see it, if a file has been included once then any object, function or member in it is defined.

require_once checks if the file is included and if so, doesn't include it again. But when would the event ever arise that someone would go 'this file has already been included so I can use the class inside it, but I'd better include it again because this script needs it'?

Am I missing something?


Solution

  • I use include_once / require_once for classes files, and include / require for html code (let's say a form for example). You shouldn't redeclare the class, but you could insert html code multiple times in your code.