Hi Sammy,

Sammy Kaye Powers wrote:
If you create a php file with the following:

<?php
header("X-foo: Bar");
echo "Foo!".PHP_EOL;

And save it as UTF-8 with BOM, interesting things happen depending on
the SAPI & configuration.

If you run it from the CLI you get an error:

PHP Warning:  Cannot modify header information - headers already sent by 
(output started at %s:1) in %s on line %d

But it doesn't seem to return the BOM to std out (but I could be doing
this part wrong). If you run it from `php -S`, and load it in a
browser, the web server returns a code point \u{feff} as the first
code point of the response body.

BOM's should not be treated as characters and should not be sent to
the output. Is there any reason this should be considered the expected
behavior? If not, I'd like to create an RFC to change it. :)

I suspect that this part of the Zend Engine is much-neglected, but PHP actually can detect the BOM, and strip it from the output, if you have zend.multibyte turned on:

https://github.com/php/php-src/blob/3b0a6dfeb2896fb204db48d11364c09942b1ad01/Zend/zend_language_scanner.l#L292

I haven't tried this myself, though.

Thanks.
--
Andrea Faulds
https://ajf.me/

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

Reply via email to