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

Codechecker complains about type-hinting in foreach loops

    XMLWordPrintable

    Details

    • Workaround:
      Hide

      Define a type for the array

      instead of:

      /** @var setting_dependency $dependency */
      foreach ($setting->get_dependencies() as $dependency)

      we can use

      /** @var setting_dependency[] $dependencies */
      $dependencies = $setting->get_dependencies();
      foreach ($dependencies as $dependency)

      not ideal but it works

      Show
      Define a type for the array instead of: /** @var setting_dependency $dependency */ foreach ($setting->get_dependencies() as $dependency) we can use /** @var setting_dependency[] $dependencies */ $dependencies = $setting->get_dependencies(); foreach ($dependencies as $dependency) not ideal but it works
    • Affected Branches:
      MOODLE_34_STABLE
    • Fixed Branches:
      MOODLE_35_STABLE

      Description

      IMHO the following type-hint should be valid:

      /** @var classname $variable */
      foreach ($somearray as $variable)

      { // ... }

      but it gives error: Inline doc block type-hinting for '$variable'

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              roperto Daniel Thee Roperto
              Reporter:
              roperto Daniel Thee Roperto
              Participants:
              Component watchers:
              moodle.com, Eloy Lafuente (stronk7)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                13/Jan/20