|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30971 Random highlight_string() bug while handling legal backslash characters
Submitted: 2004-12-03 00:56 UTC Modified: 2005-08-28 01:00 UTC
Avg. Score:4.7 ± 0.7
Reproduced:9 of 9 (100.0%)
Same Version:5 (55.6%)
Same OS:6 (66.7%)
From: Assigned:
Status: No Feedback Package: Strings related
PHP Version: 5CVS, 4CVS OS: *
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.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2004-12-03 00:56 UTC]
Bug 25725 was marked bogus due to a bad example. I am reopening it here because this is a particularly annoying bug that needs to be fixed, regardless of 'this is not an issue' sentiment within the PHP community.

When the highlight_string() engine encounters ANY \ character, even one prefixing an escape like \n (which are LEGAL, as some astute Quick Fix posters have ignored), the parser interjects warnings into highlight_string()'s output. The catch? This only happens randomly.

We rely on highlight_string() for our IRC pastebin, and I am sure this function is used a lot elsewhere. I have submitted another entry to our pastebin and was quite disappointed to see the bug's problem at once:
  Screenshot taken from

I have highlighted the problem for the QA reviewers with itchy Quick Fix fingers. Notice the 'n' sitting on a line all by itself? That's the back end of a \n sequence, and the PHP parser is erring on the \ itself. It's as if the tokenizer, when used under highlight_string(), isn't glomming \ onto its following character.

It is also only doing it on some newlines. As you can see, the newlines next to '019' (the bottom of the highlight) are parsed fine! As you can also see, the colors in the rest of the code, even on keywords that should be highlighted green like 'static' and 'function', are all messed up.

This isn't the first time we've run into this. I've taken screenshots to append to Bug 25725, but they were ignored as well. I rewind and replay them here for community benefit.

Source URL:

Nothing changed on the server between these two requests. I just refreshed until the output changed. And these are legal newlines. The example on Bug 25725 brought the itchy Quick Fix fingers out, but the submitter presented a valid point, which I reiterate here.

Highlighted fine:

    $x = 0
    $y = 1
    $z = 2

Not highlighted fine:

    $x = 0;
    $z = 2;

And as I've demonstrated, this isn't highlighted fine either:


The randomness of this problem suggests a leak or black magic within PHP itself, and I have a gut feeling this is a little more problematic than it appears at first hand. The reproduce code below is what is supposed to be highlighted in phpbug3.png.

Note: Do not flood with refresh requests, trust my screenshots.

Reproduce code:
 * The beefiest exceptioner evar.

public static function ErrorHandler(Exception $e) {
    // FIXME //
    if(file_exists($e->getFile())) {
        $line = file($e->getFile());
        $line = trim($line[$e->getLine() - 1]);
    else $line = "?";
    printf("\n\nSTOP. Uncaught exception \"%s\" in %s:%u\n" .
        "  >> %s\n" .
        "  Message: (%u) %s\n  Backtrace:\n", get_class($e), $e->getFile(),
        $e->GetLine(), $line, $e->getCode(), $e->getMessage());
    $i = 0;
    foreach($e->getTrace() as $bt)
        printf("     (#%u) %s()\n", ++$i, $bt['class'] . $bt['type'] . $bt['function'],
            $bt['file'], $bt['line']);

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-19 11:49 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.

 [2005-08-20 11:20 UTC]
I provided a working example and screenshots of both results. _Last December_. I got tired of maintaining my labs. subdomain just so these links wouldn't break. Since I hadn't heard anything on this bug I assumed nobody was going to do anything about it, so I stopped caring and went ahead and cleaned up the subdomain.

This behavior exhibits itself regardless of the containing script and is not reliably reproducable (hence the purpose of the screenshots). It's random, and does not matter in its context:


...would randomly exhibit this behavior depending on the setup.

I verified this as a CVS developer last year, I'm tired of the jaw-droppingly arrogant support here (from deleting 'irrelevant' comments to ignoring functionality bugs), so I left it to the PHP developers to do something about it.

Plopping a quick fix on this bug and looking for *another* reproduce script won't fix anything. I gave you all you need last December.

If you want the screenshots e-mail me, I'm sure I have them buried somewhere.
 [2005-08-28 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 23 01:01:29 2024 UTC