Skip to content

Commit 01dfd98

Browse files
committed
Use http_get_last_response_headers() instead of $http_response_header with PHP 8.4+
1 parent 86f9ec2 commit 01dfd98

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

bin/import-cldr-data

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,23 @@ class DocumentStorage
173173
private function fetch($path)
174174
{
175175
$url = $this->baseUrl . '/' . ltrim($path, '/');
176+
if (defined('PHP_VERSION_ID') && \PHP_VERSION_ID >= 80400) {
177+
http_clear_last_response_headers();
178+
}
176179
set_error_handler(function () {}, -1);
177180
$content = file_get_contents($url, false, $this->context);
178181
restore_error_handler();
179182
if ($content === false) {
180183
$details = '';
181-
/** @var array $http_response_header */
182-
if (!empty($http_response_header)) {
183-
$details = " - {$http_response_header[0]}";
184+
if (defined('PHP_VERSION_ID') && \PHP_VERSION_ID >= 80400) {
185+
$lastResponseHeaders = http_get_last_response_headers();
186+
} elseif (!empty($http_response_header)) {
187+
$lastResponseHeaders = $http_response_header;
188+
} else {
189+
$lastResponseHeaders = null;
190+
}
191+
if (!empty($lastResponseHeaders)) {
192+
$details = " - {$lastResponseHeaders[0]}";
184193
}
185194
throw new RuntimeException("Failed to download from {$url}{$details}");
186195
}

0 commit comments

Comments
 (0)