php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55064 Inconsistent error reporting when using highlight_xxx() functions.
Submitted: 2011-06-29 06:13 UTC Modified: -
Votes:3
Avg. Score:3.7 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: RQuadling at GMail dot com Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: 5.3.6 OS: Irrelevant
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-06-29 06:13 UTC] 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">&lt;?php
<br /></span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;comment
<br /></span>
</span>
</code>
Last error :

<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php
<br /></span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;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">&lt;?php
<br /></span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;comment
<br /></span>
</span>
</code>
Last error :

<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php
<br /></span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;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">&lt;?php
<br /></span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;comment
<br /></span>
</span>
</code>
Last error :

<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php
<br /></span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;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">&lt;?php
<br /></span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;comment
<br /></span>
</span>
</code>
Last error :

<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php
<br /></span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;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">&lt;?php
<br /></span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;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">&lt;?php
<br />
Warning: Unterminated comment starting line 2 in Z:\ts1.php on line 25
</span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;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">&lt;?php
<br /></span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;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">&lt;?php
<br /></span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;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">&lt;?php
<br /></span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;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">&lt;?php
<br /></span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;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">&lt;?php
<br /></span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;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">&lt;?php
<br /></span><span style="color: #FF9900">/*&nbsp;Broken&nbsp;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
)


Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 21:01:26 2019 UTC