474

UPDATE 2:

I have now removed the following from the .php file:

<?php error_reporting( E_ALL ); ?> 

I have set display_erros in php.ini as follows:

display_errors = On

Error reporting is set to the following in php.ini:

error_reporting = E_ALL | E_STRICT

After restarting Apache, I still get no errors/warnings.

UPDATE 1:

I have changed error_reporting in php.ini from:

error_reporting = E_ALL & ~E_DEPRECATED

to

error_reporting = E_ALL | E_STRICT

After which I restarted Apache, e.g.

/etc/init.d/apache2 restart

But the page will still not display errors/warnings of any kind.

ORIGINAL QUESTION:

The following script is generating a warning because the $err being inside the if statement. Why is this warning not being displayed on the PHP page in a web browser?

I have to look at the Apache logs to see the warning. Also, if I deliberately change the "insert into" to "delete into", it does not display an error on the PHP page. Why are the errors not displaying on the actual PHP page?

<?php error_reporting(E_ALL); ?> <html> <head> <title></title> <link rel="icon" type="image/png" href="favicon.ico"> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $err = array(); if (empty( $_POST['display_name'])) $err[] = "display name field is required"; if (empty( $_POST['email'])) $err[] = "email field is required"; if (empty( $_POST['password'])) $err[] = "password field is required"; if (!$err) { try { $DBH = new PDO("mysql:host=localhost;dbname=database1", "user", "pass"); $DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $STH = $DBH->prepare("delete into table1 (display_name, email, password) values ( :display_name, :email, :password )"); $STH->bindParam(':display_name', $_POST['display_name'], PDO::PARAM_STR, 100); $STH->bindParam(':email', $_POST['email'], PDO::PARAM_STR, 100); $STH->bindParam(':password', $_POST['password'], PDO::PARAM_STR, 100); $STH->execute(); $STH = $DBH->prepare("delete into table2 ( username, status, users_id ) values ( :username, :status, :users_id )"); $strStatus = 1; $STH->bindParam(':username', $_POST['display_name'], PDO::PARAM_STR, 100); $STH->bindParam(':status', $strStatus, PDO::PARAM_INT, 1); $STH->bindParam(':users_id', $_POST['referer'], PDO::PARAM_INT, 1); $STH->execute(); $DBH = null; } catch (PDOException $e) { echo $e->getMessage(); } header("Location: " . $_SERVER['PHP_SELF']); exit; } else { foreach ($_POST as $key => $val) { $form[$key] = htmlspecialchars($val); } } } else { $form['display_name'] = $form['email'] = $form['password'] = ''; } ?> </head> <body> <?php foreach($err as $line) { ?> <div style="error"><?php echo $line; ?></div> <?php } ?> <h1>Register</h1> <form method="post"> Referers id:<br/> <input type="text" name="referer" /><br/><br/> Name:<br/> <input type="text" name="display_name" value="<?php echo $form['display_name']; ?>" /><br/><br/> Email:<br/> <input type="text" name="email" value="<?php echo $form['email']; ?>" /><br/><br/> Password:<br/> <input type="text" name="password" value="<?php echo $form['password']; ?>" /><br/><br/> <input type="submit" value="register" /> </form> </body> </html> 
8
  • 1
    What is the current value of the display_errors INI setting? Commented Mar 25, 2011 at 21:00
  • I've just check and it is set to error_reporting = E_ALL & ~E_DEPRECATED Commented Mar 25, 2011 at 21:05
  • Please re-read my question, we already know your error_reporting setting because it is in the script. Commented Mar 25, 2011 at 21:15
  • Please see UPDATE 1: in the original question. Commented Mar 25, 2011 at 21:23
  • 2
    Please re-re-read my question. display_errors is entirely different from error_reporting. Also, your script overrides the error_reporting value set in the INI file. Commented Mar 25, 2011 at 21:27

6 Answers 6

1347

Display errors could be turned off in the php.ini or your Apache configuration file.

You can turn it on in the script:

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

You should see the same messages in the PHP error log.

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

12 Comments

Do I need to restart apache after changing the php.ini file?
already this question has been posted stackoverflow.com/questions/1053424/…
@oshirowanen ini_set() does not actually change the php.ini file, the script only "acts" like it is set like that in php.ini... From manual: Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution , and will be restored at the script's ending .
I don't know how many times I came to same answer. You helped me a lot. Thank you! :)
@Charles Why would E_ALL remove E_NOTICE? Doesn't E_ALL by itself including everything, including E_NOTICE?
|
75

I was able to get all errors via the below code:

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

4 Comments

only code that worked for me on my server (IONOS)
error_reporting(-1); should not be used. It may not work on every system. Instead should be error_reporting(E_ALL);
error_reporting(-1) should work just fine as it is given as example here: php.net/manual/en/function.error-reporting.php
The values for ini_set should actually be strings, such as ini_set('display_errors', '1'); as per documentation and this is enforced when using strict typing (eg, declare(strict_types=1);)
54

PHP errors can be displayed by any of below methods:

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

For more details:

Displaying PHP errors

1 Comment

The display_errors = on; in PHP file has syntax error.
43

Straight from the php.ini file:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Error handling and logging ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; This directive informs PHP of which errors, warnings and notices you would like ; it to take action for. The recommended way of setting values for this ; directive is through the use of the error level constants and bitwise ; operators. The error level constants are below here for convenience as well as ; some common settings and their meanings. ; By default, PHP is set to take action on all errors, notices and warnings EXCEPT ; those related to E_NOTICE and E_STRICT, which together cover best practices and ; recommended coding standards in PHP. For performance reasons, this is the ; recommend error reporting setting. Your production server shouldn't be wasting ; resources complaining about best practices and coding standards. That's what ; development servers and development settings are for. ; Note: The php.ini-development file has this setting as E_ALL. This ; means it pretty much reports everything which is exactly what you want during ; development and early testing. ; ; Error Level Constants: ; E_ALL - All errors and warnings (includes E_STRICT as of PHP 5.4.0) ; E_ERROR - fatal run-time errors ; E_RECOVERABLE_ERROR - almost fatal run-time errors ; E_WARNING - run-time warnings (non-fatal errors) ; E_PARSE - compile-time parse errors ; E_NOTICE - run-time notices (these are warnings which often result ; from a bug in your code, but it's possible that it was ; intentional (e.g., using an uninitialized variable and ; relying on the fact it is automatically initialized to an ; empty string) ; E_STRICT - run-time notices, enable to have PHP suggest changes ; to your code which will ensure the best interoperability ; and forward compatibility of your code ; E_CORE_ERROR - fatal errors that occur during PHP's initial startup ; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's ; initial startup ; E_COMPILE_ERROR - fatal compile-time errors ; E_COMPILE_WARNING - compile-time warnings (non-fatal errors) ; E_USER_ERROR - user-generated error message ; E_USER_WARNING - user-generated warning message ; E_USER_NOTICE - user-generated notice message ; E_DEPRECATED - warn about code that will not work in future versions ; of PHP ; E_USER_DEPRECATED - user-generated deprecation warnings ; ; Common Values: ; E_ALL (Show all errors, warnings and notices including coding standards.) ; E_ALL & ~E_NOTICE (Show all errors, except for notices) ; E_ALL & ~E_NOTICE & ~E_STRICT (Show all errors, except for notices and coding standards warnings.) ; E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors) ; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED ; Development Value: E_ALL ; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT ; http://php.net/error-reporting error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT 

For pure development I go for:

 error_reporting = E_ALL ^ E_NOTICE ^ E_WARNING 

Also don't forget to put display_errors to on

display_errors = On 

After that, restart your server for Apache on Ubuntu:

sudo /etc/init.d/apache2 restart 

2 Comments

"PHP 6.0.0"? Heh :-)
“For pure development @JohnMagnolia go[es] for: error_reporting = E_ALL ^ E_NOTICE ^ E_WARNING.” Are the ^ symbols concatenating the three options? If so, doesn’t E_ALL already include E_NOTICE and E_WARNING?
11

Set these on php.ini:

;display_startup_errors = On display_startup_errors=off display_errors =on html_errors= on 

From your PHP page, use a suitable filter for error reporting.

error_reporting(E_ALL); 

Filers can be made according to requirements.

E_ALL E_ALL | E_STRICT 

Comments

7

You can see a detailed description here.

ini_set('display_errors', 1); // Report simple running errors error_reporting(E_ERROR | E_WARNING | E_PARSE); // Reporting E_NOTICE can be good too (to report uninitialized // variables or catch variable name misspellings ...) error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); // Report all errors except E_NOTICE error_reporting(E_ALL & ~E_NOTICE); // Report all PHP errors (see changelog) error_reporting(E_ALL); // Report all PHP errors error_reporting(-1); // Same as error_reporting(E_ALL); ini_set('error_reporting', E_ALL); 

Changelog

  • 5.4.0 E_STRICT became part of E_ALL

  • 5.3.0 E_DEPRECATED and E_USER_DEPRECATED introduced.

  • 5.2.0 E_RECOVERABLE_ERROR introduced.

  • 5.0.0 E_STRICT introduced (not part of E_ALL).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.