array_shift() - only variables can be passed by reference in PHP5

array_shift() - only variables can be passed by reference in PHP5

by David Mudrák -
Number of replies: 1
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
Hi!
I just went thru some quick fixes necessary to run 1.5.2+ at my PHP5 box. One thing I've noticed: the behaviour of PHP has silently changed surprise during last development: only variables can be now passed to array_shift(). E.g.
$focus = "form.".array_shift(array_flip(get_object_vars($err)));
will produce PHP's Fatal error in latest versions sad.

I've found the problematic code in several places:
$ egrep -rc 'array_shift\([^$]' * | grep -v ':0$'
course/groups.php:1
grade/exceptions.php:1
lib/adodb/drivers/adodb-ldap.inc.php:3
lib/datalib.php:10
lib/magpie/rss_parse.inc:2
login/signup.php:1

Maybe PHP5 compatibility is not the issue of the day, but you clever guys developing our favourite Moodle should avoid using this traditional syntax in the future.. (fixing the current code would be welcome wink)
See Moodle bug 3900 and PHPBug-#33495 for more details on this.

David
Average of ratings: -
In reply to David Mudrák

Re: array_shift() - only variables can be passed by reference in PHP5

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Thanks David for documenting the places where you have found the fatal code. I do consider PHP5 compatability to be a serious issue. Many users seem to be hosting on servers that they may not control.  I would simply like to add my voice of encouragement to the developers to incorporate these changes to help ensure compatibility.