RE: [PHP] sloppy use of constants as strings. WAS: What does "<<<" mean?
| From: | Daevid Vincent | Date: | Tue, 01 May 2007 02:05:51 +0000 |
| Subject: | RE: [PHP] sloppy use of constants as strings. WAS: What does "<<<" mean? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-254175@lists.php.net to get a copy of this message | ||
> > > echo <<<EOF
> > > BROWSER: $_SERVER[HTTP_USER_AGENT]
> > > EOF;
> >
> > Isn't that form (sans quote marks) deprecated and frowned upon?
>
> <?php
>
> error_reporting( E_ALL );
>
> echo <<<EOF
> BROWSER: $_SERVER[HTTP_USER_AGENT]
> EOF;
>
> Why would cleaner, perfectly error free code be frowned upon?
http://us2.php.net/manual/en/language.types.array.php
"A key may be either an integer or a string. If a key is the standard
representation of an integer, it will be interpreted as such (i.e. "8" will
be interpreted as 8, while "08" will be interpreted as "08")."
I was always under the impression that using:
$_SERVER[HTTP_USER_AGENT] or $foo[myindex]
Was "bad" compared to the proper way of:
$_SERVER['HTTP_USER_AGENT'] or $foo['myindex']
Just like it's:
define('MYTHING', true);
not
define(MYTHING, true);
(again, note the ' marks)
http://us2.php.net/manual/en/function.define.php
http://us2.php.net/manual/en/language.constants.php
"If you use an undefined constant, PHP assumes that you mean the name of the
constant itself, just as if you called it as a string (CONSTANT vs
"CONSTANT"). An error of level E_NOTICE will be issued when this happens.
See also the manual entry on why $foo[bar] is wrong (unless you first
define() bar as a constant). If you simply want to check if a constant is
set, use the defined() function."
So, I think you're relying upon a little work that PHP does for you in that
an undefined CONSTANT is turned into a STRING i.e. "bad". Personally, I
*hate* that it does this work, and would love to see a little stricter
parsing done and throw a fatal error if you try to use an undefined
constant.
D.Vin