What about ...
Although there might be real problems for this, please can you
describe a concrete problem that will occur, in a library people use,
rather than a vague possible problem?
Well, both underscores and hyphens are permitted in header names - so a
library that replaces underscores with hyphens potentially mangles real
header names. (Mangling and unmangling are both lossy operations.)
For most framework users, all of the request variables are only
accessed through either a PSR7 request object or their framework
specific equivalent, and the problem of mangling/demangling can be
solved there.
Yes, that's my concern - if they don't know whether the names are already
mangled or not, they might apply the unmangling, unintentionally mangling
actual valid header names.
Besides also wasting some CPU time - no point in processing header-names if
they're already properly formatted.
Mainly, all I'm suggesting is that there be some way to tell if the names
were either never mangled, or have already been unmangled, so we can avoid
single or multiple (redundant and/or lossy) mangling/unmangling operations
in the polyfill and PSR-7 libraries.
Since this has to do with $_SERVER, it seems natural to keep it in
$_SERVER["REAL_HEADER_NAMES"], which would be set to true on PHP 8.
So in the polyfill:
if (isset($_SERVER["REAL_HEADER_NAMES"])) {
// mangle names...
unset($_SERVER["REAL_HEADER_NAMES"]);
}
And in the PSR-7 libraries:
if (isset($_SERVER["REAL_HEADER_NAMES"])) {
// use names as is
} else {
// unmangle names
}
This is just an example - I'm indifferent as to the name and location of
this value.
Someone suggested using a constant, but you can't unset a constant - for
the polyfill and PHP 8 both to be seen by a PSR-7 library as having real
header names, the polyfill needs to be able to clear that flag. (With a
constant, you'd need an additional check against php_version() - just
trying to keep this as simple as possible.)