Uploaded image for project: 'Plugins'
  1. Plugins
  2. CONTRIB-7099

PHP include/require do not require parenthesis

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Deferred
    • Affects Version/s: 3.2.5, 3.3
    • Fix Version/s: None
    • Component/s: Local: Code checker
    • Labels:
      None

      Description

      The codechecker plugin contains a sniff (IncludingFileSniff.php) that enforces the inclusion of redundant parenthesis around the path to be included.
      e.g. "require_once" must be immediately followed by an open parenthesis

      There is a common misconception about the nature of include, require, include_once, and require_once.
      None of these language constructs require parenthesis, and it can be argued that enforcing this behaviour as a matter of course is bad practice.

      _PHP manual - see examples #4 and #5 http://php.net/manual/en/function.include.php_
      "Because include is a special language construct, parentheses are not needed around its argument. Take care when comparing return value."

      _Pear coding standards - http://pear.php.net/manual/en/standards.including.php_
      "include_once and require_once are statements, not functions. Parentheses should not surround the subject filename."

      It is for a similar reason echo and print do not require the use of parenthesis (and their use can potentially break normal use of echo).

      Note: List of PHP keywords http://php.net/manual/en/reserved.keywords.php

        Attachments

          Activity

            People

            Assignee:
            davidaylmer David Aylmer
            Reporter:
            davidaylmer David Aylmer
            Participants:
            Component watchers:
            moodle.com, Eloy Lafuente (stronk7)
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: