Warning: Illegal offset type in moodlelib.php on line 769

Re: Warning: Illegal offset type in moodlelib.php on line 769

by Helen Foster -
Number of replies: 3
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
We tried downloading the revision Zbigniew mentions but found that errors were still generated. It appears that the errors were caused because the course ID being passed to the isteacher function is sometime an object. The modified function below checks if it is an object or not, and if it is, checks to see if the object has an ID property which can then be used as the key in the $USER->teacher array.

function isteacher($courseid=0, $userid=0, $includeadmin=true) {
/// Is the user a teacher or admin?
global $USER, $CFG;

if ($includeadmin and isadmin($userid)) { // admins can do anything the teacher can
return true;
}

if (empty($courseid)) {
if (isadmin() or $CFG->debug > 7) {
notify('Coding error: isteacher() should not be used without a valid course id as argument. Please notify a developer.');
}
return isteacherinanycourse($userid, $includeadmin);
}

if (!$userid) {
if ($courseid) {
if (empty($USER->id) or empty($USER->teacher)) {
return false;
}
// start of modification
if (is_object($courseid)) {
if (empty($courseid->id)) {
return false;
}
return !empty($USER->teacher[$courseid->id]);
}
// end of modification
return !empty($USER->teacher[$courseid]);
}
if (!isset($USER->id)) {
return false;
}
$userid = $USER->id;
}

return record_exists("user_teachers", "userid", $userid, "course", $courseid);
}
(Thanks to Andy for this code smile)
In reply to Helen Foster

Re: Warning: Illegal offset type in moodlelib.php on line 769

by David Jinx -
I am still getting this error, ie.
Warning: Illegal offset type in /var/www/moodle/lib/moodlelib.php on line 1854
Warning: Illegal offset type in /var/www/moodle/lib/moodlelib.php on line 1929

But it is in the calendar component, and not in the forum component. It will only show up when logged in as a teacher, not as admin or student.  Those two warning's point to the following code:

1. if (!empty($USER->teacher[$courseid])) { // Explicitly a teacher, good

Note: this if statement is in the isteacher function

2. return !empty($USER->teacheredit[$courseid]);

Note: this return statement is in the isteacheredit function

I have already tried the is_object option detailed here: http://moodle.org/mod/forum/discuss.php?d=21215&parent=118986
but I still receive the errors.

Install details:

Moodle Version: Moodle 1.5.3 (2005060230)
Apache Version: 2.0.46
php Version: 4.3.2
MySQL Version: 3.23.58

Any and all help is greatly appreciated.
In reply to Helen Foster

Re: Warning: Illegal offset type in moodlelib.php on line 769

by Paolo Oprandi -
Something similar going in Moodle 1.6 beta 5 of questionlib.php in function add_indented_names that prevent me from adding any questions to a quiz. I'll submit a bug report.

Warning: Illegal offset type in /local/data/moodle/lib/questionlib.php on line 1388
In reply to Paolo Oprandi

Re: Warning: Illegal offset type in moodlelib.php on line 769

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I can't reproduce it. I think I may have fixed it along with a bunch of other minor niggles. Can you get the latest 1.6 branch version and test it again?  Thanks.