4

I recently setup a new web server and I'm getting undefined variable error. If I use variables without initializing, it gives me an error. The source code did not change. Only the LAMP environment did. How would you solve this problem?

Thanks

webnat0
  • 2,646
  • 5
  • 29
  • 43
  • 2
    Need to shut off/lower the error checking either in the php.ini or using [error_reporting](http://php.net/manual/en/function.error-reporting.php) -- though you should be defining your variables before using them. ;p – Brad Christie Feb 21 '11 at 01:23
  • See the correct answer here: https://stackoverflow.com/a/71127489/388994 – blade Jul 14 '22 at 12:13

3 Answers3

8

you can change your error_reporting as people said, but if you want keep the default error_reporting configuration. you may use @ operator. e.g: @$post

antoniputra
  • 4,251
  • 6
  • 26
  • 31
8

Well...

  1. You should define all your variables, those warnings are there for a reason, to make you code better. Undefined variables can easily lead to typo errors in variable names.

  2. You can change the *error_reporting* level, above E_NOTICE to get rid of that, but it is highly unadvisable.

Orbling
  • 20,413
  • 3
  • 53
  • 64
7

You can set notices to not show.

error_reporting(E_ALL & ~E_NOTICE)

You should be developing with

error_reporting(E_ALL | E_STRICT)
Linga
  • 10,379
  • 10
  • 52
  • 104
Spechal
  • 2,634
  • 6
  • 32
  • 48