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

Coding style ruling about function/method return types

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Component/s: Coding style
    • Labels:

      Description

      Since Moodle 7.0 it's possible to specify returning types to functions & methods (examples from php.net):

      function sum($a, $b): float {
          return $a + $b;
      }
      

      More yet, since PHP 7.1 (so, eligible for Moodle 3.7 and up) it's also possible to use the nullify operator to allow also nulls to be returned:

      function sum($a, $b): ?float {
          return $a + $b;
      }
      

      This issue (followup of MDLSITE-5660) is about to decide if we want to rule how to write code using those return types, both spacing and the "?" symbol. Basically, between:

      A) function xxx(): [?]int <<== default syntax used in php site
      B) function xxx() : [?]int <<== already used syntax in core - privacy stuff mainly
      C) Current status, unruled. Basically any number of chars is allowed. See this fixture file to view all the crazy possibilities.

      Ciao

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                • Created:
                  Updated: