Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-75976

META: Calls passing nulls to built in functions not accepting nulls

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor Minor
    • 4.1.1
    • 4.1
    • General
    • None

      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 deprecated

      RFC: 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:

      1. Pick some are with some related stuff (say database drivers, say privacy api, say moodlelib...) where some cases have been detected.
      2. Try to fix as many of them by:
        1. 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.
        2. 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):
          1. function($nullparam) => function($nullparam ?? '')
          2. 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

            stronk7 Eloy Lafuente (stronk7)
            stronk7 Eloy Lafuente (stronk7)
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 week, 5 hours, 35 minutes
                1w 5h 35m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.