diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
index 0ba059ba8e..71a0522139 100644
--- a/src/wp-includes/functions.php
+++ b/src/wp-includes/functions.php
@@ -6287,7 +6287,7 @@ function get_file_data( $file, $default_headers, $context = '' ) {
 	}
 
 	foreach ( $all_headers as $field => $regex ) {
-		if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) {
+		if ( preg_match( '/^(?:[ \t]*<\?php)?[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) {
 			$all_headers[ $field ] = _cleanup_header_comment( $match[1] );
 		} else {
 			$all_headers[ $field ] = '';
diff --git a/tests/phpunit/data/formatting/php-open-tag-prefixed-file-header.php b/tests/phpunit/data/formatting/php-open-tag-prefixed-file-header.php
new file mode 100644
index 0000000000..dc078607c3
--- /dev/null
+++ b/tests/phpunit/data/formatting/php-open-tag-prefixed-file-header.php
@@ -0,0 +1 @@
+<?php // Template Name: Something ?>
diff --git a/tests/phpunit/tests/file.php b/tests/phpunit/tests/file.php
index 730d72c5c1..a281028d37 100644
--- a/tests/phpunit/tests/file.php
+++ b/tests/phpunit/tests/file.php
@@ -65,6 +65,25 @@ class Tests_File extends WP_UnitTestCase {
 		}
 	}
 
+	/**
+	 * @group plugins
+	 * @group themes
+	 */
+	function test_get_file_data_header_with_php_open_tag_prefix() {
+		$headers  = array(
+			'TemplateName'  => 'Template Name',
+		);
+		$actual = get_file_data( DIR_TESTDATA . '/formatting/spaces-before-php-tag-file-header.php', $headers );
+
+		$expected = array(
+			'TemplateName' => 'Something',
+		);
+
+		foreach ( $actual as $header => $value ) {
+			$this->assertSame( $expected[ $header ], $value, $header );
+		}
+	}
+
 	function is_unique_writable_file( $path, $filename ) {
 		$fullpath = $path . DIRECTORY_SEPARATOR . $filename;
 
