Forum Moderators: coopster

Message Too Old, No Replies

PHP Notice?

Undefined constants in PHP

         

sunroof

10:50 pm on Mar 21, 2008 (gmt 0)

10+ Year Member



I moved my sites from php4 to php5 and now in error_log I get a lot of PHP Notice errors of undefined constants.

1) How can I define a constant in PHP?
2) How can I set error_log not to log these errors?

Thanks a lot.

eelixduppy

11:10 pm on Mar 21, 2008 (gmt 0)



My guess is that you are getting these notices because you didn't wrap a string in quotes when it should have been. For instance, the following will produce a notice of this kind:

$_POST[var]

Because you are missing the quotes, it assumes "var" to be a constant, and when it cannot find it, php assumes that you meant to put the quotes in there and uses it as such; this however will still produce those notices. To fix it you'd just have to code it correctly :)


$_POST['var']

Question 1) To define a constant, however, you would use the define [php.net] method.

Question 2) You can turn your error reporting [php.net] down so that you do not get notified of any notifications like this with your error reporting directive in php.ini. Personally I allow everything to get logged to my error log so that I know if anything, no matter how small, goes wrong in my code. By default, the error reporting level should be set to E_ALL ^ E_NOTICE, I believe, but if it's not, then you might want to change it back to that. It will log all errors except notices.

coopster

1:37 pm on Mar 22, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I also want to add that the move to PHP5 likely had nothing to do with the reported errors. The same errors would have been thrown in PHP4 for the same reason. It has to do with error_reporting as noted.