I'm getting ready to update my wiki and noticed that extensions are not declared the same way in LocalSettings.php. I have about 57 extensions, and all but 7 use 'require_once'
From a programmatic standpoint, the difference appears to be in how PHP
will handle errors.
The require() function is identical to include(), except that it handles errors differently. If an error occurs, the include() function generates a warning, but the script will continue execution. The require() generates a fatal error, and the script will stop.
In the general scheme of things, is one a better practice over the other? Is it nuanced between extensions in such a way that some extensions need one over the other?
Yours, Chris Koerner clkoerner.com
Chris Koerner nobelx@gmail.com writes:
Please don't use W3Schools for PHP information. Information on any PHP keyword can be found by typing "http://php.net/KEYWORD" into your browser's URL bar.
For example, http://php.net/require takes you to a page that clearly explains the difference between the two:
require is identical to include except upon failure it will also produce a fatal E_COMPILE_ERROR level error. In other words, it will halt the script whereas include only emits a warning (E_WARNING) which allows the script to continue.
In the general scheme of things, is one a better practice over the other?
On my sites, I like to know as soon as possible if there is a problem. require() will give an error if a file doesn't exist instead of trying to continue. If a site continues to operate with missing files, you'll probably end up with errors that are harder to diagnose than they need to be.
Mark.
mediawiki-l@lists.wikimedia.org