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

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

 



On Mon, April 30, 2007 9:05 pm, Daevid Vincent wrote:
>> > > 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']

Those *ARE* bad, but they aren't embedded in double-quotes, nor
heredoc, which are entirely different environments.

Those are raw PHP syntax strings, with no delimiters to set them off
as "string"

> Just like it's:
>
> 	define('MYTHING', true);
>
> not
>
> 	define(MYTHING, true);

Same exact thing.

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

I'm *NOT* relying on that at all.

When it is inside of the quotes or heredoc, it is being parsed by an
entirely different parser with an entirely different grammar, with
absolutely ZERO context the same.

I'm all for making un-quoted unknown literals an E_ERROR instead of
E_NOTICE if you can convince the Internals that the
backwards-compatability break is "good"...

But don't make me add a bunch of junk to the embedded variable inside
quotes and heredoc!

PHP already "knows" that these cannot be function names, nor contants,
nor anything other than variables to be embedded there, because of the
quotes or heredoc delimiters.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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