Ivan Nachev
Ivan Nachev

Reputation: 47

How can I make it so that I can see PHP errors in the browser?

Whenever the person whose tutorials I am watching makes a mistake in his code, the error is printed in his browser. This does not happen whenever I make any mistake which results in me having to look over my code million times before I find my mistake.

Upvotes: 0

Views: 93

Answers (2)

Daniel
Daniel

Reputation: 172

Try this at the top of your code:

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

One thing to not is this doesn't make PHP show parse errors. The only way of doing this is to modify the php.ini file with this line:

display_errors = on

Upvotes: 2

1. In the Case Of Array

<?php
echo '<pre>';
print_r($debug_array);
echo '</pre>';
exit;
?>

2. In the Case Of Array

<?php
/**
 * Send debug code to the Javascript console
 */ 
function debug_to_console($data) {
    if(is_array($data) || is_object($data))
    {
        echo("<script>console.log('PHP: ".json_encode($data)."');</script>");
    } else {
        echo("<script>console.log('PHP: ".$data."');</script>");
    }
}
?>

3. Display Error Reporting

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

and in Your php.ini file display_errors = on

4.Notice + All Erorrs

error_reporting(E_ALL); OR error_reporting(-1);

5.For All Kind Of Errors

error_reporting(E_ERROR);

Upvotes: 1

Related Questions