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

PHP 8.0: Empty string does not cast to 0

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.11
    • 3.10.1
    • General, Questions, Quiz

      From https://php.watch/versions/8.0#string-number-comparison and release notes:
      https://php.watch/versions/8.0/string-number-comparison

      Non-strict comparisons between numbers and non-numeric strings now work by
      casting the number to string and comparing the strings. Comparisons between
      numbers and numeric strings continue to work as before. Notably, this means
      that `0 == "not-a-number"` is considered false now.
      RFC: https://wiki.php.net/rfc/string_to_number_comparison

      (so they changed what's converted, previously the string was coerced to number, now the opposite)

      For example, the following snippet returns true on PHP7 and false on PHP8:

      var_dump('' == 0);
      

      This causes some errors around Moodle where we expected empty string to be treated as 0.

      See sandbox: http://sandbox.onlinephpfunctions.com/code/0a8af6908807e6da5172584e6c9d0842609bf6e1

            marina Marina Glancy
            marina Marina Glancy
            Tim Hunt Tim Hunt
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            CiBoT CiBoT
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 20 minutes
                1h 20m

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