php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #67655 php_strip_whitespace outputs warnings instead of going through the error_handle
Submitted: 2014-07-19 22:25 UTC Modified: 2020-03-11 13:01 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: seld@php.net Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: seld@php.net
New email:
PHP Version: OS:

 

 [2014-07-19 22:25 UTC] seld@php.net
Description:
------------
php_strip_whitespace appears to be bypassing the error handler and output buffering. If you run it in CLI and there is a warning like "Unterminated comment starting line .." then that is output to the user with no chance to intercept.

More infos at https://github.com/composer/composer/issues/3030 and a test run showing various issues at http://3v4l.org/pS3LE

The only workaround found was to @-silence the call, which is alright but I thought I'd report it anyway because it's pretty strange behavior.

Test script:
---------------
<?php
function log_error($num, $str, $file, $line, $context = null) {
    throw new ErrorException( $str, 0, $num, $file, $line );
}
set_error_handler('log_error');
ob_start();

// uncommenting the line below might help surface the problem:
//error_reporting(-1); ini_set('display_errors', 1);

file_put_contents('test.php', '<?php /*');
$out = php_strip_whitespace('test.php');
unlink('test.php');

var_dump(ob_get_clean(), $out); 


Expected result:
----------------
string(0) ""
string(6) "<?php "

Actual result:
--------------
Warning: Unterminated comment starting line 1 in repro.php on line 9
string(0) ""
string(6) "<?php "

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-21 01:05 UTC] yohgaki@php.net
-Package: Output Control +Package: Scripting Engine problem
 [2014-07-21 01:05 UTC] yohgaki@php.net
This happens because these syntax errors are handled in Zend.
Output control is PHP feature, while language scanner is Zend.
highlight_file(), etc may have same issue.
 [2020-03-11 13:01 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2020-03-11 13:01 UTC] cmb@php.net
Well, actually this is because that warning is E_COMPILE_WARNING,
and these cannot be handled by user defined error handlers.  If it
was E_WARNING, for instance, the error handler would be called.
However, throwing an exception there would still not have the
intended result, since at the end of zend_strip() exceptions are
discarded[1]; this is done to prevent parse errors and such to
make it to scripts which call php_strip_whitespace().

The most reasonable course of action appears to update the
documentation to reflect that php_strip_whitespace() and
highlight_string() and such swallow exceptions raised by userland
callbacks.

[1] <https://github.com/php/php-src/blob/php-7.4.3/Zend/zend_highlight.c#L228-L229>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 10:01:28 2024 UTC