0

I'm experiencing a weird issue where errors are not being displayed when there are obvious errors.

This throws an error as expected:

<?php

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

hurrrrr

?>

However, this does not and just returns a blank page...

<?php

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

HUUURRRR

include('../includes/simple_html_dom.php');

$html = file_get_html('www.hurrrr.com');
foreach($html->find('.Hurrrrrrr') as $element) {
    echo $element->plaintext . '<br />';
}


?>
2
  • 2
    Syntax errors will lead to scripts not being interpreted at all. Not even the first line of it. Commented Aug 6, 2014 at 13:30
  • I totally love you name :) Commented Aug 6, 2014 at 13:40

2 Answers 2

2

PHP is run in two main "passes".

  1. Parse the code.

  2. Run the code.

If the code cannot be parsed (hurrrrr), then it cannot be run.
If it cannot be run, then display_errors and error_reporting cannot be set.
If they cannot be set, then errors cannot be shown.

This is why it is preferable to set these in your php.ini file (or whatever configuration file is used for your setup). Indeed display_startup_errors cannot be set via ini_set() because by the time ini_set is called, startup has already finished!

Sign up to request clarification or add additional context in comments.

3 Comments

I'm not sure I understand. Both examples should result in code that cannot being parsed but in the first example I get "Notice: Use of undefined constant HUUURRRR - assumed 'HUUURRRR' in /var/www/test.php on line 12"
This error should be reflected in the webserver logs though; and running a php -l against the file will also identify the error
Thanks, Mark. This was really helpful. I did not know I could do php -l. Cheers!
2

You have to change the display_errors settings in php.ini.

If you are in localhost and use WAMP, right-clicking on WAMP icon and selecting php.ini may not solve your problem, as you should go to your wamp/bin/php*/php.ini and change this file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.