SV: [PHP-WIN] should i be concerned about these "Use of undefinedconstant xxxx - assumed 'xxx'..." notice warnings???
| From: | Henrik Hornemann | Date: | Tue, 29 Apr 2003 09:17:55 +0000 |
| Subject: | SV: [PHP-WIN] should i be concerned about these "Use of undefinedconstant xxxx - assumed 'xxx'..." notice warnings??? | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-19711@lists.php.net to get a copy of this message | ||
I would guess that the cause of the notice is the reference to an array like $foo[csuh_tag] instead
of the correct $foo['csuh_tag']. If you like to keep your code clean, you should correct
these minor details.
regards Henrik Hornemann
> -----Oprindelig meddelelse-----
> Fra: Per Lundberg [mailto:per@nobolt.com]
> Sendt: 29. april 2003 09:14
> Til: Leo G. Divingracia III
> Cc: php-windows@lists.php.net
> Emne: Re: [PHP-WIN] should i be concerned about these "Use of
> undefinedconstant xxxx - assumed 'xxx'..." notice warnings???
>
>
> 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
>