diff --git a/core/lib/Drupal/Core/Database/StatementPrefetch.php b/core/lib/Drupal/Core/Database/StatementPrefetch.php
index 18dd582..14c64f7 100644
--- a/core/lib/Drupal/Core/Database/StatementPrefetch.php
+++ b/core/lib/Drupal/Core/Database/StatementPrefetch.php
@@ -284,7 +284,7 @@ class StatementPrefetch implements Iterator, StatementInterface {
         case PDO::FETCH_OBJ:
           return (object) $this->currentRow;
         case PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE:
-          $class_name = array_unshift($this->currentRow);
+          $class_name = array_shift($this->currentRow);
           // Deliberate no break.
         case PDO::FETCH_CLASS:
           if (!isset($class_name)) {
diff --git a/core/modules/system/lib/Drupal/system/Tests/Database/DatabaseTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Database/DatabaseTestBase.php
index 2fff06b..3c53321 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Database/DatabaseTestBase.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Database/DatabaseTestBase.php
@@ -127,6 +127,15 @@ abstract class DatabaseTestBase extends WebTestBase {
       ))
       ->execute();
 
+    db_insert('test_classtype')
+      ->fields(array(
+      'classname' => 'Drupal\system\Tests\Database\FakeRecord',
+      'name' => 'Kay',
+      'age' => 26,
+      'job' => 'Web Developer',
+    ))
+      ->execute();
+
     db_insert('test_task')
       ->fields(array('pid', 'task', 'priority'))
       ->values(array(
diff --git a/core/modules/system/lib/Drupal/system/Tests/Database/FetchTest.php b/core/modules/system/lib/Drupal/system/Tests/Database/FetchTest.php
index c6f647a..374e989 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Database/FetchTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Database/FetchTest.php
@@ -90,6 +90,27 @@ class FetchTest extends DatabaseTestBase {
     $this->assertIdentical(count($records), 1, t('There is only one record.'));
   }
 
+  /**
+   * Confirm that we can fetch a record into a new instance of a custom class.
+   * The name of the class is determined from a value of the first column.
+   *
+   * @see Drupal\system\Tests\Database\FakeRecord
+   */
+  function testQueryFetchClassType() {
+    $records = array();
+    $result = db_query('SELECT classname, name, job FROM {test_classtype} WHERE age = :age', array(':age' => 26));
+    foreach ($result->fetchAll(PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE) as $record) {
+      $records[] = $record;
+      if ($this->assertTrue($record instanceof FakeRecord, t('Record is an object of class FakeRecord.'))) {
+        $this->assertIdentical($record->name, 'Kay', t('Kay is found.'));
+        $this->assertIdentical($record->job, 'Web Developer', t('A 26 year old Web Developer.'));
+      }
+    }
+
+    $this->assertIdentical(count($records), 1, t('There is only one record.'));
+    $this->assertTrue(!isset($record->classname), t('Classname field not found, as intended.'));
+  }
+
   // Confirm that we can fetch a record into an indexed array explicitly.
   function testQueryFetchNum() {
     $records = array();
diff --git a/core/modules/system/tests/modules/database_test/database_test.install b/core/modules/system/tests/modules/database_test/database_test.install
index 867d813..c799a62 100644
--- a/core/modules/system/tests/modules/database_test/database_test.install
+++ b/core/modules/system/tests/modules/database_test/database_test.install
@@ -87,6 +87,44 @@ function database_test_schema() {
     ),
   );
 
+  $schema['test_classtype'] = array(
+    'description' => 'A duplicate version of the test table, used for fetch_style PDO::FETCH_CLASSTYPE tests.',
+    'fields' => array(
+      'classname' => array(
+        'description' => "A custom class name",
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'name' => array(
+        'description' => "A person's name",
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'age' => array(
+        'description' => "The person's age",
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'job' => array(
+        'description' => "The person's job",
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+    ),
+    'primary key' => array('job'),
+    'indexes' => array(
+      'ages' => array('age'),
+    ),
+  );
+  
   $schema['test_one_blob'] = array(
     'description' => 'A simple table including a BLOB field for testing BLOB behavior.',
     'fields' => array(
