RE: [PHP] Advice on Constants - Notice: Undefined Constant
| From: | John W. Holmes | Date: | Thu, 10 Apr 2003 00:06:59 +0000 |
| Subject: | RE: [PHP] Advice on Constants - Notice: Undefined Constant | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-143239@lists.php.net to get a copy of this message | ||
> > Notices are generated when you have error_reporting in
> > your php.ini set to E_ALL & ~E_NOTICE
[snip]
> Yes I'm aware of all the bases regarding the notices and I am aware of
the
> constant function. What I was asking what is the best way to resolve
my
> situation? I want to do proper coding to the best of my ability. So
even
> with your remark about forms with hidden fields, I agree but can this
not
> be
> resolved? Maybe doing a define(variable, 0).
Just make sure $variable has a value before you use it anywhere... plain
and simple.
If you're going to say:
If($variable > 0)
Make sure $variable has a value so you don't get the NOTICE message.
As for the warnings about 'Undefined Index' that results from you using
an index in an array that doesn't exist.
Echo $_POST['foo']
When there is no key of 'foo' in the $_POST array. Check and see if a
variable is set with isset() before you do anything with it.
> I'm just looking for direction and the best solution. I assume that
these
> notices are nothing major but should not be occurring if I would have
done
> things correctly. Is this correct?
Yep.
> Or should I be taking the notices as just a notice to let me know and
that
> my code is fine?
No, you shouldn't. Sure, it'll run fine at certain error_reporting
levels, but it can also be fixed to run in any configuration of PHP.
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/