General developer forum

Warning calling $DB->get_records

 
Picture of Pedro Remedios
Warning calling $DB->get_records
 

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: -
Picture of Mike Churchward
Re: Warning calling $DB->get_records
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developersGroup Plugins guardiansGroup 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));

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Warning calling $DB->get_records
Group Core developersGroup Documentation writersGroup Particularly helpful MoodlersGroup 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.
 
Average of ratings: -
Picture of Pedro Remedios
Re: Warning calling $DB->get_records
 

Thanks for the tips guys!

 
Average of ratings: -