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

PHP 8.0: Empty string does not cast to 0

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.10.1
    • Fix Version/s: 3.11
    • Component/s: General, Questions, Quiz
    • Labels:

      Description

      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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              marina Marina Glancy
              Reporter:
              marina Marina Glancy
              Peer reviewer:
              Tim Hunt Tim Hunt
              Integrator:
              Sara Arjona (@sarjona) Sara Arjona (@sarjona)
              Tester:
              CiBoT CiBoT
              Participants:
              Component watchers:
              Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan, Tim Hunt, Andrew Lyons, Dongsheng Cai, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Tim Hunt, Andrew Lyons, Dongsheng Cai, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                17/May/21

                  Time Tracking

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