Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-45997

Iterators used in foreach (invalid PHP code)

XMLWordPrintable

    • BACKEND Sprint 18

      The following snippet contains reference semantics on an iterator in a foreach loop:

      https://github.com/moodle/moodle/blob/MOODLE_26_STABLE/lib/navigationlib.php#L869

      As of PHP 5.2, this is not legitimate code, and should throw an exception, which it also does using another PHP implementation such as HHVM:

      "Fatal error: An iterator cannot be used with foreach by reference in /***/lib/navigationlib.php on line 879"

      That it does not do so under the Zend implemenation is perhaps due to a bug. Another possibility is that the $node variable in the snippet (seemingly) never gets assigned, and hence the exception is dodged under Zend. In either case, this should most likely be changed to avoid breakage if these rules are ever enforced in 5.2+ runtimes.
      EDIT: There are other examples where the iterator is clearly being assigned, and yet no error is signalled. Almost certainly a bug in Zend.

            csvan Christopher Svanefalk
            csvan Christopher Svanefalk
            David Monllaó David Monllaó
            Votes:
            2 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved:

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