Not seeing php error message insde script tag

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RichTWebGuy
Forum Newbie
Posts: 3
Joined: Fri May 21, 2010 3:11 pm

Not seeing php error message insde script tag

Post 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>
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Not seeing php error message insde script tag

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
RichTWebGuy
Forum Newbie
Posts: 3
Joined: Fri May 21, 2010 3:11 pm

Re: Not seeing php error message insde script tag

Post 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>
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Not seeing php error message insde script tag

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Not seeing php error message insde script tag

Post by AbraCadaver »

That'll teach me not to test HTML output on the command line :oops:
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
RichTWebGuy
Forum Newbie
Posts: 3
Joined: Fri May 21, 2010 3:11 pm

Re: Not seeing php error message insde script tag

Post 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.
Post Reply