Skip to content

Commit ab67ce0

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

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

bin/import-cldr-data

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,24 @@ 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+
$varName = 'http_response_header';
188+
$lastResponseHeaders = ${$varName};
189+
} else {
190+
$lastResponseHeaders = null;
191+
}
192+
if (!empty($lastResponseHeaders)) {
193+
$details = " - {$lastResponseHeaders[0]}";
184194
}
185195
throw new RuntimeException("Failed to download from {$url}{$details}");
186196
}

0 commit comments

Comments
 (0)