Uploaded image for project: 'Moodle Community Sites'
  1. Moodle Community Sites
  2. MDLSITE-2716

Coding style: require/include description does not mention require_once.

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Low Low
    • Coding style
    • 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...

            poltawski Dan Poltawski
            quen Sam Marshall
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.