Zastaralé $http_response_header
PHP 8.5 zastaralo proměnnou $http_response_header, která obsahuje hlavičky posledního HTTP požadavku. Místo ní je k dispozici funkce http_get_last_response_headers(). Co když potřebujeme zpětně kompatibilní kód? Tímhle si nepomůžeme, protože zastaralost $http_response_header se zjišťuje už při kompilaci:
<?php $headers = (function_exists('http_get_last_response_headers') ? http_get_last_response_headers() : $http_response_header); ?>
Tohle varování o zastaralosti vyřeší, ale kód ve starších verzích nefunguje, proměnná se nenaplní:
<?php $var = 'http_response_header'; $headers = (function_exists('http_get_last_response_headers') ? http_get_last_response_headers() : $$var); ?>
Jedině tohle je řešení, které ve starších verzích funguje a v nové nezpůsobí varování:
<?php if (function_exists('http_get_last_response_headers')) { $http_response_header = http_get_last_response_headers(); } ?>
Jakub Vrána, Řešení problému, 12.7.2026
Diskuse je zrušena z důvodu spamu.

