0

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.

  • 4
    Possible duplicate of [How do I get PHP errors to display?](http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) – Don't Panic May 18 '17 at 19:35

2 Answers2

2

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
Daniel
  • 162
  • 9
  • I assume that unless I put it in the header file that I include in almost every page, it's only gonna work in the page that I've pasted it in? – Ivan Nachev May 18 '17 at 19:26
  • That's correct. If you place it into a file that has no interaction with the page you are on, it has no idea that the code there exists, meaning it doesn't realise you want to display errors. – Daniel May 18 '17 at 19:28
  • 2
    @IvanNachev yes, but you can search for `display_errors` and `error_reporting` in your `php.ini` and set them there, so it will always work for any PHP execution. Remember to restart apache or your web service. – matiaslauriti May 18 '17 at 19:28
  • 1
    @matiaslauriti Of course going into your php,ini file and setting them is easy enough to do, it can also be a pain having to restart your server when it's easy enough to just have a function or include that calls them being set when you need them. – Daniel May 18 '17 at 19:30
1

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);
RïshïKêsh Kümar
  • 4,194
  • 1
  • 20
  • 31