How to change the display of php errors?

1

Since I formatted the server I can no longer change the way the errors were displayed. Today the errors are presented as follows

andIwouldlikeittobedisplayedasinWAMP

My php.ini file is configured as follows:

display_errors = On
error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE
html_errors = On

Version of php

PHP Version 5.5.13-1~dotdeb.1

Server

Debian 7 "Wheezy"
    
asked by anonymous 11.06.2014 / 19:03

2 answers

1

To do this you must install xDebug. As it is full of dependencies we have to install some things first

Step 1: Install PEAR

  

apt-get install php-pear

Step 2: Install PHP5-DEV

  

apt-get install php5-dev

Step 3: Install Libcurl3

  

apt-get install libcurl3-openssl-dev

Step 4: Install PECL-HTTP (optional)

  

pecl install pecl_http

Step 5: Install xDebug: D

  

pecl install xdebug

Step 6: Add the following line in your php.ini

  

zend_extension = xdebug.so

And that's it, now your php will display the errors with the orange box, the cascade arrays, will be able to debug the code among other things ...

Sources:
Chirale
MKFOSTER
xDebug - Official Website

    
11.06.2014 / 20:21
2

You should use set_error_handler and set a function of yours to treat and display errors as you wish

Source: link

<?php
// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
    if (!(error_reporting() & $errno)) {
        // This error code is not included in error_reporting
        return;
    }

    //CUSTOMIZAR SUAS TELAS DE ERRO AQUI

    switch ($errno) {
    case E_USER_ERROR:
        echo "<b>My ERROR</b> [$errno] $errstr<br />\n";
        echo "  Fatal error on line $errline in file $errfile";
        echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
        echo "Aborting...<br />\n";
        exit(1);
        break;

    case E_USER_WARNING:
        echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
        break;

    case E_USER_NOTICE:
        echo "<b>My NOTICE</b> [$errno] $errstr<br />\n";
        break;

    default:
        echo "Unknown error type: [$errno] $errstr<br />\n";
        break;
    }

    /* Don't execute PHP internal error handler */
    return true;
}

// function to test the error handling
function scale_by_log($vect, $scale)
{
    if (!is_numeric($scale) || $scale <= 0) {
        trigger_error("log(x) for x <= 0 is undefined, you used: scale = $scale", E_USER_ERROR);
    }

    if (!is_array($vect)) {
        trigger_error("Incorrect input vector, array of values expected", E_USER_WARNING);
        return null;
    }

    $temp = array();
    foreach($vect as $pos => $value) {
        if (!is_numeric($value)) {
            trigger_error("Value at position $pos is not a number, using 0 (zero)", E_USER_NOTICE);
            $value = 0;
        }
        $temp[$pos] = log($scale) * $value;
    }

    return $temp;
}

// set to the user defined error handler
$old_error_handler = set_error_handler("myErrorHandler");

// trigger some errors, first define a mixed array with a non-numeric item
echo "vector a\n";
$a = array(2, 3, "foo", 5.5, 43.3, 21.11);
print_r($a);

// now generate second array
echo "----\nvector b - a notice (b = log(PI) * a)\n";
/* Value at position $pos is not a number, using 0 (zero) */
$b = scale_by_log($a, M_PI);
print_r($b);

// this is trouble, we pass a string instead of an array
echo "----\nvector c - a warning\n";
/* Incorrect input vector, array of values expected */
$c = scale_by_log("not array", 2.3);
var_dump($c); // NULL

// this is a critical error, log of zero or negative number is undefined
echo "----\nvector d - fatal error\n";
/* log(x) for x <= 0 is undefined, you used: scale = $scale" */
$d = scale_by_log($a, -2.5);
var_dump($d); // Never reached
?>
    
11.06.2014 / 19:12