diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 3e3853a..3ed3ac8 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -15,6 +15,7 @@
 use Drupal\Core\Language\Language;
 use Drupal\Core\Lock\DatabaseLockBackend;
 use Drupal\Core\Lock\LockBackendInterface;
+use Drupal\user\Plugin\Core\Entity\User;
 
 /**
  * @file
@@ -2046,12 +2047,14 @@ function drupal_get_hash_salt() {
  * @return Object - the user object.
  */
 function drupal_anonymous_user() {
-  $user = new stdClass();
-  $user->uid = 0;
-  $user->hostname = ip_address();
-  $user->roles = array();
-  $user->roles[DRUPAL_ANONYMOUS_RID] = DRUPAL_ANONYMOUS_RID;
-  return $user;
+  $values = array(
+    'uid' => 0,
+    'hostname' => ip_address(),
+    'roles' => array(
+      DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID,
+    ),
+  );
+  return new User($values, 'user');
 }
 
 /**
diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 8172073..cc60af2 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -2650,8 +2650,6 @@ function _template_preprocess_default_variables() {
     'title_prefix' => array(),
     'title_suffix' => array(),
     'db_is_active' => !defined('MAINTENANCE_MODE'),
-    // User module overrides these when it is loaded.
-    'user' => drupal_anonymous_user(),
     'is_admin' => FALSE,
     'logged_in' => FALSE,
   );
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 9ee6f81..f728e8a 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -1609,7 +1609,7 @@ function comment_preprocess_block(&$variables) {
 function comment_prepare_author(Comment $comment) {
   // The account has been pre-loaded by CommentRenderController::buildContent().
   $account = $comment->uid->entity;
-  if (!$account) {
+  if (!$account || $account->uid == 0) {
     $account = entity_create('user', array('uid' => 0, 'name' => $comment->name->value, 'homepage' => $comment->homepage->value));
   }
   return $account;
diff --git a/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php b/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php
index a4bfd52..15894ad 100644
--- a/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php
+++ b/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php
@@ -33,7 +33,7 @@ function setUp() {
     parent::setUp();
 
     $this->account = $this->drupalCreateUser();
-    $this->anonymous = entity_create('user', (array) drupal_anonymous_user());
+    $this->anonymous = drupal_anonymous_user();
   }
 
   /**
