Page 1 of 1
Not seeing php error message insde script tag
Posted: Fri May 21, 2010 3:17 pm
by RichTWebGuy
Given a sample example like this, where class XXXXXXXXXXXXXXXXXXXXXXXXXXX doesn't exist, you never see the error message because the html error message is stuck between <script> ... </script>. Took a couple minutes to realize this.
Anyone ever find a nice solution to this? Thanks
<?php ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
</head>
<body>
<?php
print "<script type=\"text/javascript\">";
$obj = new XXXXXXXXXXXXXXXXXXXXXXXXXXX;
print "</script>";
?>
</body>
Re: Not seeing php error message insde script tag
Posted: Fri May 21, 2010 3:33 pm
by AbraCadaver
RichTWebGuy wrote:Given a sample example like this, where class XXXXXXXXXXXXXXXXXXXXXXXXXXX doesn't exist, you never see the error message because the html error message is stuck between <script> ... </script>.
What?!?!
[text]Fatal error: Class 'XXXXXXXXXXXXXXXXXXXXXXXXXXX' not found[/text]
Try enabling display_errors.
Re: Not seeing php error message insde script tag
Posted: Fri May 21, 2010 3:42 pm
by RichTWebGuy
I believe error reporting is all turned on. If I move the offending line outside the script tag I do see the error.
As is, I get a blank page. If I view->source, I get the following. I'm assuming I don't see anything because the <script> tag stops the browser from displaying anything.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
</head>
<body>
<script type="text/javascript"><br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Class 'XXXXXXXXXXXXXXXXXXXXXXXXXXX' not found in E:\WebSiteDevelopment\xampp173\xampplite\htdocs\test\www\test-php\index.php on line <i>8</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0011</td><td bgcolor='#eeeeec' align='right'>327328</td><td bgcolor='#eeeeec'>{main}( )</td><td title='E:\WebSiteDevelopment\xampp173\xampplite\htdocs\test\www\test-php\index.php' bgcolor='#eeeeec'>..\index.php<b>:</b>0</td></tr>
</table></font>
Re: Not seeing php error message insde script tag
Posted: Fri May 21, 2010 3:51 pm
by cpetercarter
Yes, the browser will think that anything between <script> tags is javascript, and will try to execute it.
The moral is to make sure that anything which goes to the browser between <script> tags is in fact JavaScript.
Re: Not seeing php error message insde script tag
Posted: Fri May 21, 2010 3:54 pm
by AbraCadaver
That'll teach me not to test HTML output on the command line

Re: Not seeing php error message insde script tag
Posted: Sat May 22, 2010 9:03 am
by RichTWebGuy
Maybe there's a case where this won't work, but as I use xdebug, adding this to php.ini helped me with this problem
error_prepend_string = "</script>"
It will put in a </script> when it's not needed, but so far the messages appear either way.