safe icon indicating copy to clipboard operation
safe copied to clipboard

http_response_header missing

Open diversen opened this issue 2 years ago • 2 comments

Great library, thanks :+1:

When using safe functions you lose access to $http_response_header. $http_response_header is created in the local scope.

I guess there is no fix for this? I could not find anything about this issue after searching a bit.

<?php

require_once "vendor/autoload.php";

use function Safe\file_get_contents;

file_get_contents("https://google.com");
var_dump($http_response_header);

// -> Warning: Undefined variable $http_response_header in ...

It is the same with e.g. fopen.

diversen avatar Mar 17 '23 20:03 diversen

This is some horrible PHP magic and I'm not sure how to emulate it, but keeping the issue open mostly to keep track of it...

shish avatar Feb 03 '25 13:02 shish

This was likely superseded by http_get_last_response_headers() in php >= 8.4.

For older versions, we considered a pattern of \Safe\some_function2(...): array to return more than just one result value.

/**
 * ...
 *
 * @return array{string, array} The function returns the read data.
 * @throws FilesystemException
 *
 */
function file_get_contents2(string $filename, bool $use_include_path = false, $context = null, int $offset = 0, ?int $length = null): array
{
// ...

    return [$safeResult, $http_response_header];
}

standa avatar Oct 21 '25 09:10 standa