Notice: Trying to get property of non-object in

Notice: Trying to get property of non-object in

by Joe Boyle -
Number of replies: 2

Hi all,

I am using Moodle 3.3.1.  Today I found a new notice on the top page of one of my courses:

Notice: Trying to get property of non-object in /home/jboyle/public_html/moodle/lib/completionlib.php on line 255


The code in completionlib.php is line 255 identified:

    /**

     * Constructs with course details.

     *

     * When instantiating a new completion info object you must provide a course

     * object with at least id, and enablecompletion properties. Property

     * cacherev is needed if you check completion of the current user since

     * it is used for cache validation.

     *

     * @param stdClass $course Moodle course object.

     */

    public function __construct($course) {

        $this->course = $course;

        $this->course_id = $course->id;    (this is line 255)

    }


    /**

     * Determines whether completion is enabled across entire site.

     *

     * @return bool COMPLETION_ENABLED (true) if completion is enabled for the site,

     *     COMPLETION_DISABLED (false) if it's complete

     */

    public static function is_enabled_for_site() {

        global $CFG;

        return !empty($CFG->enablecompletion);

    }


Does anyone know how to remove this notice message?  What damage can it do?

Best

Joe Boyle

   




Average of ratings: -
In reply to Joe Boyle

Re: Notice: Trying to get property of non-object in

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

Unfortunately, on its own, there isn't enough information  there to determine what is causing the problem. Was there more information in the message? Perhaps a calling tree of what code was being used?

The error indicates something called the function, in this case creating a new 'completion_info' object, without passing a valid course object. More than likely, this is from a plugin you have added to your site. If no other problems are happening, your site will run fine, but some plugin may not be able to use completion criteria correctly.

You can prevent the message from being displayed by going to your Site administration / Development / Debugging setting and turn off "Display debug messages". While you are there, you should probably lower the "Debug messages" setting as well.

mike

In reply to Mike Churchward

Re: Notice: Trying to get property of non-object in

by Joe Boyle -

Mike,

Thank you for taking time to respond to my post.  It was exactly what I needed.  With you suggestions I was able to check and update plugins and remove the warning message with sensitive path information in public_ htlm.

Was there more information in the message? - Yes I found more information listed in another spot- it gave several more lines of code of where the problem lies- however since I updated the plugins I no longer can find it.   I believe it was under reports, or course completion status, or notifications.  Since I updated the plugins the warning message details are no longer there.

I sense after the cron runs several times the warning will disappear.   

On a personal note- greetings from Marquette MI- we are one of your northern neighbors.  My wife grew up near Hamilton (Ancaster) and we still have family scattered around the area.  Kitchner, Toronto, Barrie, and Mississauga)

Thanks Again

Joe  Boyle






Average of ratings: Useful (1)