Edit report at https://bugs.php.net/bug.php?id=55064&edit=1
ID: 55064
Updated by: cmb@php.net
Reported by: RQuadling at GMail dot com
Summary: Inconsistent error reporting when using
highlight_xxx() functions.
-Status: Open
+Status: Verified
Type: Bug
Package: Scripting Engine problem
Operating System: Irrelevant
PHP Version: 5.3.6
Block user comment: N
Private report: N
New Comment:
See <https://3v4l.org/gHjNG> for a revised script (most
notably it
calls error_clear_last()), and its results. The only difference
is for error_reporting=-1 and display_errors=1, where
highlight_file() raises E_WARNING, while highlight_string() does
not. This is because for some reason error_reporting is
temporarily set to E_ERROR for highlight_string(), but not for
highlight_file(). Maybe just an oversight in the respective
commit[1]? It seems to me this inconsistency should be fixed, but
given the long standing behavior, which might be deliberately
employed by existing code, not for a stable PHP version (at least
not for PHP 7.4)
Note that the difference as of PHP 8.0.0 is because $badScript
no longer raises E_WARNING, but rather a ParseError[1].
[1] <https://github.com/php/php-src/commit/b03d3fa5b7a2bbfc69c069c992a39b2c3b1b8967>
[2] <https://3v4l.org/KE5Kq>
Previous Comments:
------------------------------------------------------------------------
[2011-06-29 06:13:23] RQuadling at GMail dot com
Description:
------------
Calling highlight_xxx() with content that, if executed as a normal PHP script,
would generate an error, results in the error being available to
error_get_last(), even though, no actual PHP error has been generated by THIS
code.
Even if all error reporting has been disabled in this script.
Whilst it there is a user note covering that error_get_last() will capture any
error, even if it is suppressed, there is no error for highlight_xxx(), except
when you have error_reporting set to show errors, display_errors are set AND you
are using highlight_file() (rather than highlight_string()) to display some
code.
So, 2 issues.
1 - Inconsistent error reporting between highlight_file() and highlight_string()
when error_reporting is enabled and errors are displayed.
2 - Errors generated from non executed code are reported as errors in this
script even though no error is output (with 1 exception).
I found this when looking into the iconv() notices generated by PhD for fa and
ro Windows CHM building.
Test script:
---------------
<?php
$badScript = '<?php
/* Broken comment
';
file_put_contents('./badScript.php', $badScript);
function examine($text, $filename, $errorReporting, $displayErrors) {
// Report all errors and display them.
error_reporting($errorReporting);
ini_set('display_errors', $displayErrors);
ini_set('log_errors', $displayErrors);
echo
'error_reporting = ', $errorReporting, PHP_EOL,
'display_errors = ', $displayErrors, PHP_EOL,
'log_errors = ', $displayErrors, PHP_EOL, PHP_EOL,
// Highlight the text
highlight_string($text, True), PHP_EOL,
// What is the last known error?
'Last error is for highlight_string() if it is on line 19 :', PHP_EOL,
print_r(error_get_last(), True), PHP_EOL,
// Highlight the file
highlight_file($filename, True), PHP_EOL,
// What is the last known error?
'Last error is for highlight_file() if it is on line 25 :', PHP_EOL,
print_r(error_get_last(), True), PHP_EOL;
}
examine($badScript, './badScript.php', -1, 1);
examine($badScript, './badScript.php', -1, 0);
examine($badScript, './badScript.php', 0, 1);
examine($badScript, './badScript.php', 0, 0);
unlink('./badScript.php');
// Turn off all error reporting, display and logging.
error_reporting(0);
ini_set('display_errors', 0);
ini_set('log_errors', 0);
// Generate an error.
echo mktime(), PHP_EOL, 'Last error is for mktime() if it is on line 43 : ', PHP_EOL,
print_r(error_get_last(), True), PHP_EOL;
Expected result:
----------------
error_reporting = -1
display_errors = 1
log_errors = 1
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br /></span><span style="color:
#FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error :
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br /></span><span style="color:
#FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error :
error_reporting = -1
display_errors = 0
log_errors = 0
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br /></span><span style="color:
#FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error :
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br /></span><span style="color:
#FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error :
error_reporting = 0
display_errors = 1
log_errors = 1
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br /></span><span style="color:
#FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error :
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br /></span><span style="color:
#FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error :
error_reporting = 0
display_errors = 0
log_errors = 0
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br /></span><span style="color:
#FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error :
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br /></span><span style="color:
#FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error :
1309341644
Actual result:
--------------
error_reporting = -1
display_errors = 1
log_errors = 1
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br /></span><span style="color:
#FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error is for highlight_string() if it is on line 19 :
Array
(
[type] => 128
[message] => Unterminated comment starting line 2
[file] => Z:\ts1.php
[line] => 19
)
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br />
Warning: Unterminated comment starting line 2 in Z:\ts1.php on line 25
</span><span style="color: #FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error is for highlight_file() if it is on line 25 :
Array
(
[type] => 128
[message] => Unterminated comment starting line 2
[file] => Z:\ts1.php
[line] => 25
)
error_reporting = -1
display_errors = 0
log_errors = 0
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br /></span><span style="color:
#FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error is for highlight_string() if it is on line 19 :
Array
(
[type] => 128
[message] => Unterminated comment starting line 2
[file] => Z:\ts1.php
[line] => 19
)
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br /></span><span style="color:
#FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error is for highlight_file() if it is on line 25 :
Array
(
[type] => 128
[message] => Unterminated comment starting line 2
[file] => Z:\ts1.php
[line] => 25
)
error_reporting = 0
display_errors = 1
log_errors = 1
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br /></span><span style="color:
#FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error is for highlight_string() if it is on line 19 :
Array
(
[type] => 128
[message] => Unterminated comment starting line 2
[file] => Z:\ts1.php
[line] => 19
)
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br /></span><span style="color:
#FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error is for highlight_file() if it is on line 25 :
Array
(
[type] => 128
[message] => Unterminated comment starting line 2
[file] => Z:\ts1.php
[line] => 25
)
error_reporting = 0
display_errors = 0
log_errors = 0
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br /></span><span style="color:
#FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error is for highlight_string() if it is on line 19 :
Array
(
[type] => 128
[message] => Unterminated comment starting line 2
[file] => Z:\ts1.php
[line] => 19
)
<code><span style="color: #000000">
<span style="color: #0000BB"><?php
<br /></span><span style="color:
#FF9900">/* Broken comment
<br /></span>
</span>
</code>
Last error is for highlight_file() if it is on line 25 :
Array
(
[type] => 128
[message] => Unterminated comment starting line 2
[file] => Z:\ts1.php
[line] => 25
)
1309342054
Last error is for mktime() if it is on line 43 :
Array
(
[type] => 2048
[message] => mktime(): You should be using the time() function instead
[file] => Z:\ts1.php
[line] => 43
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55064&edit=1