0

I have PHP errors enabled like so:

ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);

But the default behavior is for PHP to stick the errors in the places where they occur. So if for example I had the following markup and both variables being called are undefined:

<html>
    <head>
        <title><?= $title ?></title>
    </head>
    <body>
        <?= $content ?>
    </body>
</html>

The output will be like so:

<html>
    <head>
        <title>Notice: undefined variable title...</title>
    </head>
    <body>
        Notice: undefined variable content...
    </body>
</html>

Instead I want the errors to appear in one place like so:

<html>
    <head>
        <title></title>
    </head>
    <body>
        <div class="php-errors">
            Notice: undefined variable title...<br />
            Notice: undefined variable content...
        </div>
    </body>
</html>

Is there any setting in PHP (or some other way) to set the place where the errors will show?

  • 6
    Shouldn't fixing the errors be a higher priority? – John Conde May 08 '14 at 16:10
  • @John Conde I'm trying to make it easier for developers to notice them by styling them appropriately. I don't see why this isn't a valid question. –  May 08 '14 at 16:13
  • You could make a separate page that displays the error log in the content area. Or you could use something like this: http://stackoverflow.com/questions/1241728/can-i-try-catch-a-warning – jeroen May 08 '14 at 16:14
  • PHP errors are `` with class `xdebug-error`. You could probably use JavaScript with some styling to place them appropriately. – John Bupit May 08 '14 at 16:17
  • @JohnBupit: that's only if you are using xdebug. – Léo Lam May 08 '14 at 16:22
  • Yes. I think that's the best that can be done. But even that won't handle parse errors that cause the code to die, before the JavaScript is _echoed_. – John Bupit May 08 '14 at 16:34

2 Answers2

0

Unfortunately, there's no setting like this.
PHP interpreter echoes the errors and notices immediately when they happen in PHP code.

Oleg Dubas
  • 2,320
  • 1
  • 10
  • 24
0

You can try this

<?
$error = array();
global $error;?>
<html>
<head>
    <title<? if(isset($title)){ echo $title;} else { array_push($error,$title); } ?></title>
</head>
<body>
   <? if(isset($body)){ echo $title;} else { array_push($error,$body); } ?>
   <? echo print_r($error);?>
</body>