trampgeek / moodle-qtype_coderunner

CodeRunner: A moodle quiz question type that runs student-submitted program code in a sandbox to check if it satisfies a given set of tests.
GNU General Public License v2.0
209 stars 121 forks source link

Deprecated: ucwords(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/moodle/question/type/coderunner/renderer.php on line 741 #180

Open timhunt opened 1 year ago

timhunt commented 1 year ago

We are seeing this notice for some questions, running with PHP 8.1

Deprecated: ucwords(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/moodle/question/type/coderunner/renderer.php on line 741

It seems that the code which determines $currentlanguage is getting null, and then ucwords does not like that. Obviously, changing to ucwords($currentlanguage ?? ''); make the notice go away, but that might hide a real issue. @trampgeek, I though I would check with you before changing anything.

(Also, while looking at this, I noticed there were two similar but different chunks of code at https://github.com/trampgeek/moodle-qtype_coderunner/blob/7ba87a110d33ce4ef5002a2365b2e3d594e5febe/renderer.php#L97 and https://github.com/trampgeek/moodle-qtype_coderunner/blob/7ba87a110d33ce4ef5002a2365b2e3d594e5febe/renderer.php#L508. I wonder if it would be worth moving that into a helper function?

trampgeek commented 1 year ago

Thanks for checking Tim. Indeed there must be an underlying problem for this to be happening. It implies that either the student's answer or the sample answer is being displayed in an unknown language, which at very least will mean no syntax colouring.

Much of the complexity, and the reason for the two somewhat different bits of code, stems from the multilanguage question type. This was initially a temporary hack but - as they so often do - it stuck around. I'm inclined to suspect the multilanguage question is the cause of the problem you're seeing but I can't immediately see how. Do you have a repeatable scenario that leads to this problem? If not, are you able to confirm please whether anyone in your institution is using multilanguage questions? We never use them ourselves, except for the in-house programming contest question type.

And certainly there is room for some refactoring here. But I'd first like to know what's causing the problem you're seeing.