Error reporting based on characters preceding php open tag

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rprice
    New Member
    • Mar 2010
    • 2

    Error reporting based on characters preceding php open tag

    Hey everyone,
    I am using .phtml files for templating, and I discovered that a php tag that is preceded with the combination of: any character, equals sign, either double or single quote, will result in odd error reporting behavior. Calling an incorrect function will terminating the script and will not display any error message in the browser. (Only for the condition described above. Otherwise it will report correctly.)

    Try this code to duplicate the error: (Assuming error_reporting is set to E_ALL)

    With href=" before <?php. The script terminates without displaying an error.
    Code:
    <p>one</p>
    <p><a href="<?php notAFunc('two') ?>"></a></p>
    <p>three</p>
    Now without the " before <?php. This script terminates and display the error.
    Code:
    <p>one</p>
    <p><a href=<?php notAFunc('two') ?>"></a></p>
    <p>three</p>
    I have this problem across my entire system, and I'm at least glad to know where the errors were mysteriously disappearing to. Does anyone know what the problem is? Thanks so much!
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    When this happens, does the PHP error show in the source of the document?

    If the PHP error is printed into attribute quote-marks inside the HTML markup, the error -- or at least a part of it -- may be parsed as the value of that attribute, rather than output to be displayed.

    For instance, if I do this:
    [code=php]<?php
    ini_set('displa y_errors' ,true);
    error_reporting (E_ALL);
    ?>
    <a href="<?php idontexist(); ?>">Linkage!</a>[/code]
    The first word of the error message, which happens to be a <br> tag, becomes the value of the href attribute. The rest of the message, however, breaks the HTML markup. It is injected into the <a> tag, where it doesn't belong, and leaves the HTML parser to either disregard it, or to try fix it.

    The browsers handle this differently. IE decides to dissregard the <a> tag and display the error as text; Firefox compensates by closing the <a> tag when it detects the error and use the rest of it as the text for the link. Chrome just disregards the whole thing and displays nothing. (Chrome's behavior is probably the "best" out of the three. - Browsers should just display things as they are, not try to "guess" what to do with broken code.)

    Comment

    • rprice
      New Member
      • Mar 2010
      • 2

      #3
      Thanks Atli,
      No, this is not an html issue, it is not displaying in the source at all. Perhaps its a bug with the version of php running on my server, because your example does not work for me either, simply a blank html source.

      I just experimented with it some more and the error will be output when if the code read something like this:

      Code:
      <p>one</p>
      <p>href="<?php notAFunc('two') ?></p>
      <p>three</p>
      But when you then put this inside the p tag, instead of after the p tag, it does not output. Like this:
      Code:
      <p>one</p>
      <p href="<?php notAFunc('two') ?></p>
      <p>three</p>
      So it seems that php is trying to help me by not displaying errors when within an html attribute. Is that possibly a feature?

      Comment

      Working...