By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,462 Members | 1,126 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,462 IT Pros & Developers. It's quick & easy.

Error reporting based on characters preceding php open tag

P: 2
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.
Expand|Select|Wrap|Line Numbers
  1. <p>one</p>
  2. <p><a href="<?php notAFunc('two') ?>"></a></p>
  3. <p>three</p>
  4.  
Now without the " before <?php. This script terminates and display the error.
Expand|Select|Wrap|Line Numbers
  1. <p>one</p>
  2. <p><a href=<?php notAFunc('two') ?>"></a></p>
  3. <p>three</p>
  4.  
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!
Mar 22 '10 #1
Share this Question
Share on Google+
2 Replies


Atli
Expert 5K+
P: 5,058
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:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. ini_set('display_errors' ,true);
  3. error_reporting(E_ALL);
  4. ?>
  5. <a href="<?php idontexist(); ?>">Linkage!</a>
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.)
Mar 22 '10 #2

P: 2
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:

Expand|Select|Wrap|Line Numbers
  1. <p>one</p>
  2. <p>href="<?php notAFunc('two') ?></p>
  3. <p>three</p>
  4.  
But when you then put this inside the p tag, instead of after the p tag, it does not output. Like this:
Expand|Select|Wrap|Line Numbers
  1. <p>one</p>
  2. <p href="<?php notAFunc('two') ?></p>
  3. <p>three</p>
  4.  
So it seems that php is trying to help me by not displaying errors when within an html attribute. Is that possibly a feature?
Mar 22 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.