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

The result of core_user::is_real_user is inconsistent

    XMLWordPrintable

Details

    Description

      Code may speak better than words, so here it is

          public static function is_real_user($userid, $checkdb = false) {
              global $DB;
       
              if ($userid < 0) {
                  return false;
              }
              if ($checkdb) {
                  return $DB->record_exists('user', array('id' => $userid));
              } else {
                  return true;
              }
          }
      

      For $userid = 0, the method will return True if $checkdb is False, else it will return False.

      I advocate that it should return False for a userid of 0 as it is not present in the database. This was discovered when I evaluated the possibility of using this method for checking whether a user was meant to be in the database without performing any DB query.

      Attachments

        Activity

          People

            amaia Amaia Anabitarte
            fred Frédéric Massart
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            Andrew Lyons Andrew Lyons
            CiBoT CiBoT
            Adrian Greeve, David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo, David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo, David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              14/Jan/19