-
Improvement
-
Resolution: Fixed
-
Low
-
None
http://docs.moodle.org/dev/Coding_style#Require_.2F_include
Two problems:
1. This does not mention that you should use require_once except for config.php, which should use require.
2. I think there should be an example of correctly requiring another file.
Suggest rewrite of this paragraph:
Any other include/require should use an absolute path starting with $CFG->dirroot or $CFG->libdir or path starting with _FILE_ or _DIR_. Relative includes starting with "../" can sometimes behave strangely under PHP, so it is safer to avoid them. Our CLI script must not use relative config.php paths starting with "../".
To this:
Any other include/require should use a path starting with _DIR_ or an absolute path starting with $CFG->dirroot or $CFG->libdir. Relative includes starting with "../" can sometimes behave strangely under PHP, so should not be used. Our CLI scripts must not use relative config.php paths starting with "../".
For library files in normal usage, require_once should be used (this is different from config.php which should always use 'require' as above). Examples:
require_once(_DIR_ . '/locallib.php');
require_once($CFG->libdir . '/filelib.php');
NOTE: I don't know if there's something wrong with Jira or what but I had to use Firefox to make the select box for components unhidden in order to submit this issue, nice...
- has a non-specific relationship to
-
MDLSITE-2261 Do not allow require_once at the top level of lib.php, and other frequently included files
-
- Open
-
-
CONTRIB-7421 Start checking that config.php is only included via require()
-
- Closed
-