1

I made a huge mistake by mixing result with results and it took me around 4 hours to finally find the bug.

So here is the question, in PHP, is it possible that I can enforce PHP to report errors if I use an undefined/uninitialized variable.

thank you

5 Answers 5

3

Set error reporting to E_ALL and ensure that display_errors in php.ini is on.

php.ini

display_errors = On

PHP code

// If you cannot access the php.ini file
// you can do this within your PHP code instead
@ini_set('display_errors' '1');
error_reporting(E_ALL);

The default setting you have right now probably excludes notices, the kind of errors PHP raises on uninitialized variables, which could be something like this:

error_reporting(E_ALL & ~E_NOTICE);
Sign up to request clarification or add additional context in comments.

2 Comments

Hello BoltClock, Where is the best place I put the setting? I have a constant.php that is included by almost all php scripts. Is that a good method to insert the setting into that include file? thank you
You can place it in a config file or constants file that you know will be included in all of your scripts.
2

In a development environment I prefer using error_reporting(-1). Which reports all PHP errors.

1 Comment

+1 For the benefit of the doubt, this is equivalent to error_reporting(E_ALL | E_STRICT) as E_ALL by itself does not include E_STRICT.
1

yes, use error_reporting() and set it to E_ALL, like this:

 error_reporting(E_ALL);

Comments

1

Set error reporting to report all errors. Either in php.ini or at runtime using error_reporting(E_ALL)

Comments

1

it already does report an error. something like this:

"Notice:  Undefined variable: a in C:\wamp\www\testcenter\index.PHP on line 40"

maybe you didn't go specific enough. but you should try error_reporting(-1); as as if enforces the php to show some recomendations. a piece from the php manual about E_STRICT errors:

Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.

just remember that error_reporting(-1); shows more errors than error_reporting(E_ALL); because E_STRICT errors are not included in the E_ALL constraint.

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.