error: call to undefined function str_contains() MOODLE 3.10

The interactive book content is not responding due to the following error: call to undefined function str_contains(). This occurs only when re-entering the content. According to my research, this is due to the PHP version, which needs to be 8, as I have Moodle version 3.10 and do not have that version of PHP. I would appreciate your prompt attention to this matter. Thank you very much.

 

Content types: 
otacke's picture

Hi Felipe!

Your assumption is correct. `str_contains` is a function that was introduced with PHP 8 and is not available in earlier versions.

Unfortunately, you do not provide more information about where in the code the error occurs (which you should have learned with the error message).

Anyway, I can make the assumption that you are not using the H5P plugin for moodle, but moodle's own custom H5P integration. I assume that, because I am not aware of H5P itself using any PHP 8 only function - moodle on the other hand does.

In turn, that would mean that you should reach out to moodle HQ, because H5P Group had no part in developing moodle's custom H5P integration.

However, I highly doubt that this issue will be tackled by them by not using `str_contains`. PHP 7 reached its end of life in November 2022. That means it does not receive any fixes for bugs and security issues. Aa a consequence, it is highly advisable for you (or your web provider) to migrate your server to PHP 8 as soon as possible or your server poses a potential security liability for you and your users. And when PHP 8 is running, the issue that you mention will be resolved automatically.

Best,

Oliver

Hi Oliver,

That assumption is incorrect; Moodle 3.10 was released before PHP 8.0 and therefore would obviously not contain any function calls that were introduced in PHP 8.0. While I am not associated with Felipe in any way, we as well saw this error on hosted Moodle sites running on PHP versions lower than 8.0. This error is occurring as part of the mod_hvp plugin, and specifically, in the H5P libraries included in the plugin. The relevant commit that introduces a call to str_contains() is here: https://github.com/h5p/h5p-php-library/commit/c9a4e03ff6bb488893d35a289d...

I've created a pull request to fix this issue here: https://github.com/h5p/h5p-php-library/pull/193

And for your reference, here is the entire error trace:

Exception - Call to undefined function str_contains() More information about this error Debug info: Error code: generalexceptionmessage Stack trace: line 5042 of /mod/hvp/library/h5p.classes.php: Error thrown line 4977 of /mod/hvp/library/h5p.classes.php: call to H5PContentValidator->_filter_xss_attributes() line ? of unknownfile: call to H5PContentValidator->_filter_xss_split() line 4909 of /mod/hvp/library/h5p.classes.php: call to preg_replace_callback() line 4348 of /mod/hvp/library/h5p.classes.php: call to H5PContentValidator->filter_xss() line 4707 of /mod/hvp/library/h5p.classes.php: call to H5PContentValidator->validateText() line 4799 of /mod/hvp/library/h5p.classes.php: call to H5PContentValidator->validateGroup() line 4707 of /mod/hvp/library/h5p.classes.php: call to H5PContentValidator->validateLibrary() line 4550 of /mod/hvp/library/h5p.classes.php: call to H5PContentValidator->validateGroup() line 4707 of /mod/hvp/library/h5p.classes.php: call to H5PContentValidator->validateList() line 4550 of /mod/hvp/library/h5p.classes.php: call to H5PContentValidator->validateGroup() line 4707 of /mod/hvp/library/h5p.classes.php: call to H5PContentValidator->validateList() line 4707 of /mod/hvp/library/h5p.classes.php: call to H5PContentValidator->validateGroup() line 4799 of /mod/hvp/library/h5p.classes.php: call to H5PContentValidator->validateGroup() line 2264 of /mod/hvp/library/h5p.classes.php: call to H5PContentValidator->validateLibrary() line 102 of /mod/hvp/classes/view_assets.php: call to H5PCore->filterParameters() line 71 of /mod/hvp/classes/view_assets.php: call to mod_hvp\view_assets->getfilteredparameters() line 44 of /mod/hvp/view.php: call to mod_hvp\view_assets->__construct()

 

otacke's picture

You're absolutely correct in both cases. I obviously only checked the latest version of moodle, not 3.10. And it also seems that github does only search the master branch, hence I missed the `str_contains` in the dedicated moodle branch.

If I were in H5P Group's shoes though, I'd not be sure whether I'd revert this. Yes, of course, moodle before version 4.3 does not require PHP 8 to be used. However, as I mentioned, PHP 7 reached its end of life in November 2022 and has not received security updates in over a year. Servers still running it may be security threats. Same goes for moodle 3.10 which is not supported anymore and which does not receive security fixes. IMHO it would make more sense to suggest to upgrade the outdated platform than to "fix" the issue just to adhere to what an outdated version of moodle says it supports.