From:             
Operating system: Irrelevant
PHP version:      5.3.6
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:Inconsistent error reporting when using highlight_xxx() 
functions.

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
)


-- 
Edit bug report at https://bugs.php.net/bug.php?id=60009&edit=1
-- 
Try a snapshot (PHP 5.2):            
https://bugs.php.net/fix.php?id=60009&r=trysnapshot52
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=60009&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=60009&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=60009&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=60009&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=60009&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=60009&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=60009&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=60009&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=60009&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=60009&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=60009&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=60009&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=60009&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=60009&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=60009&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=60009&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=60009&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=60009&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=60009&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=60009&r=mysqlcfg

Reply via email to