-
Bug
-
Resolution: Done
-
Minor
-
4.1
-
None
-
MOODLE_401_STABLE
-
MOODLE_401_STABLE
We have defined this issue as META because surely it will deserve a bunch of small issues (subtasks) to be done towards completion (agreed informally between marina and stronk7.
This is the definition in the php81 changelog:
. Passing null to a non-nullable argument of a built-in function is
deprecated. This matches the behavior of user-defined functions, where null
is never accepted by non-nullable arguments.
user-defined functions.var_dump(str_contains("foobar", null));
// Deprecated: Passing null to parameter #2 ($needle) of type string
// is deprecatedRFC: https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg
For sure this is the most notable change between 8.0 and 8.1 in terms of impact in codebase and it will be hard to find all cases. No matter of that some are clear and we'll proceed with them as follows:
- Pick some are with some related stuff (say database drivers, say privacy api, say moodlelib...) where some cases have been detected.
- Try to fix as many of them by:
- Analyse if the the problem can be fixed in the caller or in the code around, not making the call when going to pass null.
- If point above is not clear (many callers, impossible to guarantee...)... then, there are 2 way to fix it in the call, both with similar results. Apply for any of them, note that in the 2 alternatives we apply for empty string as default (how the function originally behaved):
- function($nullparam) => function($nullparam ?? '')
- function($nullparam) => function((string)$nullparam)
And, basically, that's all. Let's see how many cases we can find and fix.
And, also, be noted that, similarly with other cases in php 8.0, it's impossible to discover all the cases programatically, so all the work here will be based on tests outputs, web server logs and things like that.
Ciao
- is child of
-
MDL-77840 base64_encode() raised an error if null is passed as argument on PHP 8.1
-
- Closed
-