Bug #74312 [Com]: Filter BOMs out of PHP output
| From: | furun at arcor dot de | Date: | Sat, 25 Mar 2017 22:06:26 +0000 |
| Subject: | Bug #74312 [Com]: Filter BOMs out of PHP output | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-208072@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74312&edit=1
ID: 74312
Comment by: furun at arcor dot de
Reported by: furun at arcor dot de
Summary: Filter BOMs out of PHP output
Status: Open
Type: Bug
Package: Unicode Engine related
Operating System: Win7
PHP Version: 7.0.17
Block user comment: N
Private report: N
New Comment:
So countless developers have to care about this, instead of php in central point...
In my case, the error came form a automatic update of a plugin form a third party.
Previous Comments:
------------------------------------------------------------------------
[2017-03-25 21:48:35] nikic@php.net
IIRC it is possible to strip BOMs by using zend.multibyte together with zend.detect_unicode.
However, I would strongly recommend against doing this. Instead, you should adjust whatever tooling
you use to not insert BOMs for UTF-8 files. BOMs are meaningless for UTF-8 and Unicode recommends
against their use.
------------------------------------------------------------------------
[2017-03-25 21:29:53] furun at arcor dot de
I understand, but should this be a dogma in this case?
In practice, a file has to be opened to process it, or in other words, php care about opening a
source file to check if there is <?php code. The file handler could make a exception if a
php-file is processed?
I can not think of any practical use of this behafior, if a BOM must be send to output, it can be
done in code... So it would be real-live solution.
And dependent of the editor software behavior, no BOM can cause issues too. So would be nice if a
BOM can be present in a PHP file, and be ignored in the output.
I speculate it is a common and often appearing issue, so maybe deserves a exceptional treatment.
(Thanks for your VERY quick response, this was the fastest ever ;-)
(And sorry if a ask more, i am not a deep PHP-Dev insider.)
------------------------------------------------------------------------
[2017-03-25 21:08:18] spam2 at rhsoft dot net
This is simply not possible because the BOM is not part of the php output at all - php don't
and must not care about anything outside of <?php ?>
------------------------------------------------------------------------
[2017-03-25 21:01:59] furun at arcor dot de
Description:
------------
PHP send the BOM (before the tag "<?php") to the output. This is a source for some very
strange buggy behavior, which are sometimes very difficult to find, because a developer searches
errors first in the code it self and not in a mostly invisible BOM.
(I searched a "bug" in a image creating script for long time, before i found the BOM-Bug
in a third party plugin far away from the "buggy code". The common "Headers already
sent" error caused by the BOM are still confusing, but easier to find then a corrupted binary
file.)
I would suggest that PHP filters every BOM from PHP output.
(Or is there any reason not to do so i not know of?)
Test script:
---------------
(Use any file with BOM)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74312&edit=1