Hi,
first of all, I must drop a
BIG ALARM here! Inside moodle/lib/adodb/adodb.inc.php there are TWO GetAssoc() functions! Looking at code, they are:
function &GetAssoc($sql, $inputarr=false,$force_array = false, $first2cols = false)
and:
function &GetAssoc($force_array = false, $first2cols = false)
And, if I'm not wrong you are "mixing them" in this discussion, perhaps causing some troubles!
After reading a bit about the problem (in PHP bugs and
some info from jonlim's blog, it seems that, under PHP 4.4 and PHP 5.1 (and above), results of a function can be returned by reference
only if they are references.
Coming back to both functions above, the first one is a method under the ADOConnection class and the second one is a method under the ADORecordSet class.
The first one seems to properly return a reference to an array (see the line before the return), so it shouldn't be a problem.
But the second one returns just directly an array and that's exactly the "forbidden fruit" under PHP 4.4.0 and up! So the function to be patched is exactly
function &GetAssoc($force_array = false, $first2cols = false)
Anyway, perhaps it could be better to, instead of changing the declaration of the function from reference to value, causing copies of really BIG (result sets!) objects to be created all the time (and causing some potential problems if such objects have to be modified in other scopes) to change the function a bit in order to make it returns references instead of values.
To do so, I suggest this change, just modify the:
return $results;
line at the end of the function above to:
$refresults =& $results;
return $refresults;
Doing this we have created a pointer (reference) to the $results array and such reference will be returned by the function (accomplishing PHP 4.4.0 new laws).
IMPORTANT WARNING: My suggested change hasn't been tested at all (because I haven't found any 4.4.0 version for my Mac) and it's 100% hypothetical (looking the code it could cause other problems like "pointers to pointers"...) so, my personal recommendations are:
- For MOODLERS: Use the simpler change from:
function GetAssoc($force_array = false, $first2cols = false)
to
function GetAssoc($force_array = false, $first2cols = false)
- For DEVELOPERS: Analyse my suggested change, perhaps it's the correct way, perhaps no. Only one idea...
Ciao
PD: I hope I'm not doing things more and more confusing, and that the function to change is the one I've showed you here. I apologises for not being able to test it!
Any feedback (patch applied, OS, PHP and Moodle versions) will be absolutely welcome, of course!