Strange, one expression generates exception but another one not [closed]
I've faced some difficulty...
function generateExceptionOrError() {
throw new Exception();
}
Code below will display Fatal error: Uncaught exception 'E开发者_C百科xception'
:
<? generateExceptionOrError();?>
Code below will also display Fatal error: Uncaught exception 'Exception'
:
<?=generateExceptionOrError();?>
But another code below will be silent and wouldn't output any information about unhandled Excetions. It would display absolute nothing, blank page... Of course, I suppose that Exception is generated, but why it is not displayed!?
<link rel="stylesheet" href="<?=generateExceptionOrError();?>" type="text/css">
Why? What am I missing?
Thank you
UPDATED: There is not difference exception is generated in method or another kind of errors. The same situation.
One thing I've notice in testing is that if an exception occurs inside the "
's of an elements attribute, the entire element is not displayed as well as any output afterwards. It seems it might be a browsers/html quirk. Try running your script on the command line and see what output you get.
Example:
<html>
<head>
<link rel="stylesheet" href="<?php generateExceptionOrError() ?>" type="text/css">
</head>
<body>
</body>
</html>
Outputs:
<html>
<head>
Running this on the command line outputs:
<html>
<head>
<link rel="stylesheet" href="PHP Fatal error: Uncaught exception 'Exception' with message 'aaa' in /var/www/projects/test.php:4
Stack trace:
#0 /var/www/projects/test.php(11): generateExceptionOrError()
#1 {main}
thrown in /var/www/projects/test.php on line 4
Notice the <link rel="stylesheet" href="
which is what you would have expected.
This could be at the root of your issue.
the error is there you just cant see it. use firebug or view the source and you will see something like this in your header
精彩评论