Csvan foreach semantics

Fixes the use of illegal pointer semantics in foreach loops throughout Moodle. This makes it possible to get Moodle closer to running under stricter PHP runtimes, such as HHVM.