On 2/3/15 3:33 AM, Julien Pauli wrote:
On Mon, Feb 2, 2015 at 6:19 PM, Ferenc Kovacs <tyr...@gmail.com> wrote:

About $php_errormsg , we have error_get_last().
About $http_response_headers, we have no replacement.

Well, we sort of do. You can get header information from the http context stream metadata:

  $fh = fopen($urlPath, 'r', false, $context);
  $metadata = stream_get_meta_data($fh);
  $content = stream_get_contents($fh);
  fclose($fh);

$metadata['wrapper_data'] will include the headers. From an ease-of-use standpoint, $http_reponse_header gives you immediate access to headers when the previous operation was a stream based HTTP request (via fopen, or even file_get_contents()).

Why not get rid of both ?
I mean, those variables magically appearing into your code are born from C,
where libc usually give access to errno and errstr variables (which are
often implemented as macros).

We could, but it would be nice to add some kind of easy to use replacement for the "last stream operation", which essentially is the best/most common use case for $http_response_header after the fact that it is magically conjured into local scope.

For example, right now, to get headers from a http stream request, its as ease as:

$content = file_get_contents('http://php.net/');
var_dump($http_response_header);

I think a nice replacement for that would be supporting (at least):

$content = file_get_contents('http://php.net/');
$header = stream_get_meta_data()['wrapper_data'];

By passing null to stream_get_meta_data(), it would use metadata from the last request made with streams (in the same way $http_response_header is allocated).

Thats just a thought for that. I no other suggestion for the error stuff as I'd forgotten that even existed.

-ralph

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to