3ilogiclms / moodle-block_learning_plan

This plugin serves as a database and plan for all learning activities in the organziation, where such activities are organized for a more structured learning program.
8 stars 12 forks source link

Undefined property: stdClass::$text in block_learning_plan.php on line 51 #20

Closed michael-milette closed 8 years ago

michael-milette commented 8 years ago

When I go to the Front page with a learning plan block on it, I get the following error when debugging is set to developer mode:

Notice: Undefined property: stdClass::$text in /var/www/moodle/blocks/learning_plan/block_learning_plan.php on line 51

This is for version 2014082003 that I just downloaded from GitHub.

3ilogiclms commented 8 years ago

Dear Michael,

We've tested it on Moodle 2.7 and Moodle 2.9 and didn't experience this issue that you posted. Can you please specify your PHP version and anything which help us to diagnose this issue?.

Regards, 3i Logic LMS Team

michael-milette commented 8 years ago

I really don't think this is a PHP version issue but perhaps a PHP configuration difference. I am not ready to troubleshoot your environment to figure out why you are not seeing the error at this time.

That said, I will be happy to provide you with an explanation of why the error is occurring as well as a solution.

If you look at your source code, you will notice that,on line 45 of block_learning_plan, you have:

$this->content = new stdClass;

Then on line 51, you are attempting to append to a string which has not yet been initialized.

$this->content->text .= html_writer::link(...

Hence, PHP gives you an Undefined Property notice. The solution of course is to simply initialize the string before you start appending to it. If you insert the following somewhere between line 45 and 51 (except inside the "if (!strpos($pageurl, '='))" section) , the error will go away:

$this->content->text = '';

Let me know if you have any questions or concerns.

Best regards,

Michael

michael-milette commented 8 years ago

An alternative solution is to simply remove the period on line 51:

Change:

 $this->content->text .= html_writer::link(...

to:

 $this->content->text = html_writer::link(...
3ilogiclms commented 8 years ago

Dear Michael,

We've tested it on PHP version 5.4 and 5.5 and its working fine on PHP version 5.4 but in 5.5 it showing notice. We've fixed this issue by initializing $this->content->text = ''; after object creation on line number 46.

Thank you for contribution.

Regards, 3i Logic LMS Team

michael-milette commented 8 years ago

Thank you!