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

            Assignee:
            amaia Amaia Anabitarte
            Reporter:
            fred Frédéric Massart
            Peer reviewer:
            Sara Arjona (@sarjona)
            Integrator:
            Andrew Nicols
            Tester:
            CiBoT
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              14/Jan/19