RE: sloppy use of constants as strings. WAS: What does "<<<" mean?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> > > 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux