Bug #79718 [NEW]: header_register_callback behaves differently for requests with no output

From: Date: Fri, 19 Jun 2020 17:48:37 +0000
Subject: Bug #79718 [NEW]: header_register_callback behaves differently for requests with no output
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227561@lists.php.net to get a copy of this message
From: brianlmoon Operating system: Linux PHP version: 7.4.7 Package: Output Control Bug Type: Bug Bug description:header_register_callback behaves differently for requests with no output Description: ------------ When a request has no output (a redirect or 204 no content for example), or the request method is HEAD (even if the request would have generated output normally), autoloading inside the callback provided to header_register_callback fails. For requests with output, autoloading works as expected. Test script: --------------- <?php error_reporting(-1); ini_set("display_errors", true); header("Location: /foo"); header("X-Bar: 2"); spl_autoload_register(function($class) { include __DIR__."/Foo.php"; }); header_register_callback(function() { header("X-Baz: 3"); header("X-Foo: ".Foo::BAR); }); if(!empty($_GET["output"])) { echo "test"; } /* Foo.php <?php class Foo { const BAR = 1; } */ Expected result: ---------------- The following headers are returned for all requests regardless if there is output or not. X-Bar: 2 X-Baz: 3 X-Foo: 1 For example, with output: < HTTP/1.1 302 Found < Server: nginx/1.17.10 < Date: Fri, 19 Jun 2020 17:45:39 GMT < Content-Type: text/html; charset=UTF-8 < Transfer-Encoding: chunked < Connection: keep-alive < Location: /foo < X-Bar: 2 < X-Baz: 3 < X-Foo: 1 < Strict-Transport-Security: max-age=31536000; includeSubdomains < * Connection #0 to host labs.moonspot.net left intact test Actual result: -------------- < HTTP/1.1 302 Found < Server: nginx/1.17.10 < Date: Fri, 19 Jun 2020 17:46:28 GMT < Content-Type: text/html; charset=UTF-8 < Transfer-Encoding: chunked < Connection: keep-alive < Location: /foo < X-Bar: 2 < X-Baz: 3 < Strict-Transport-Security: max-age=31536000; includeSubdomains < <br /> <b>Fatal error</b>: Uncaught Error: Class 'Foo' not found in /xxx/public/test.php:16 Stack trace: #0 [internal function]: {closure}() #1 {main} thrown in <b>/xxx/public/test.php</b> on line <b>16</b><br /> -- Edit bug report at https://bugs.php.net/bug.php?id=79718&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79718&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79718&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79718&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79718&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79718&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79718&r=support Expected behavior: https://bugs.php.net/fix.php?id=79718&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79718&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79718&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79718&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79718&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79718&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79718&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79718&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79718&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79718&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79718&r=mysqlcfg

« previous php.bugs (#227561) next »