2

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,568
  • 5
  • 28
  • 42
  • 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

3 Answers3

8

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,077
  • 9
  • 48
  • 97
Spechal
  • 2,466
  • 4
  • 28
  • 45
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,025
  • 3
  • 50
  • 64
6

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,081
  • 5
  • 25
  • 31