Warning calling $DB->get_records

Warning calling $DB->get_records

by Pedro Remedios -
Number of replies: 3

Hi,

I'm getting the following debug message:

Notice: Only variables should be passed by reference in /var/www/html/moodle/mod/telemedia/locallib.php on line 85

This is my line 85:

$DB->get_records('role_assignments', array("roleid"=>reset(get_archetype_roles($config->teacherrole))->id, "userid"=>$user->id))
What is wrong with this statement?

Any help appreciated.

Regards,

Pedro

Average of ratings: -
In reply to Pedro Remedios

Re: Warning calling $DB->get_records

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers

My guess would be the complex value you are passing as the value of 'roleid'.

Who not split that up? Something like:


$role = reset(get_archetype_roles($config->teacherrole));
$records = $DB->get_records('role_assignments', array("roleid" => $role->id, "userid" => $user->id));

In reply to Pedro Remedios

Re: Warning calling $DB->get_records

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes, the idiom of using 'reset' to get the first element of an array does not like being passed the result of a function call.

$archetyperoles = get_archetype_roles($config->teacherrole);
$DB->get_records('role_assignments', array("roleid"=>reset($archetyperoles)->id, "userid"=>$user->id))
will work without warnings.