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

The result of core_user::is_real_user is inconsistent

XMLWordPrintable

      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.

            amaia Amaia Anabitarte
            fred Frédéric Massart
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            Andrew Lyons Andrew Lyons
            CiBoT CiBoT
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

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