Re: should i be concerned about these "Use of undefined constant xxxx - assumed 'xxx'..." notice warnings???
| From: | Per Lundberg | Date: | Tue, 29 Apr 2003 07:13:33 +0000 |
| Subject: | Re: should i be concerned about these "Use of undefined constant xxxx - assumed 'xxx'..." notice warnings??? | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-19708@lists.php.net to get a copy of this message | ||
On Tue, 2003-04-29 at 06:00, Leo G. Divingracia III wrote:
> i'm getting these "notices":
>
> Use of undefined constant csuh_tag - assumed 'csuh_tag' in
> c:\foxserv\www\inventory\test3.php on line 20
>
> they work and all, but i want to run clean and true PHP code. should i
> worry? or just let it go? the stuff works...
Your intentions are good, and pure code should never output warnings or
errors.
This specific warning is probably caused by the very common mistake of
doing like this:
define(csuh_tag, 20);
print csuh_tag;
The problem is that in the first line, you are using an undefined
constant - namely csuh_tag. It is not defined, and it is not
technically a string. The correct way to write it is like this:
define('csuh_tag', 20);
print csuh_tag;
This code will not generate any warnings. This mistake is a very common
cause for programming errors (especially with people who are not so
familiar with programming) so the PHP developers decided do implement a
"hack" which means that a constant that has not been defined will have
the value of the name... to make the code work as the user expected.
Personally, I believe this is a very bad feature and it would have been
much better to spit out a compile error so that it would be obvious that
the construct is invalid. But then again, I am a bit more strict in my
thinking than most of the PHP developers...
Hope this helps.
--
Best regards,
Per Lundberg / Capio ApS
Phone: +46-18-4186040
Fax: +46-18-4186049
Web: http://www.nobolt.com
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc