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

From: Date: Tue, 01 May 2007 08:10:48 +0000
Subject: Re: sloppy use of constants as strings. WAS: What does "<<<" mean?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-254179@lists.php.net to get a copy of this message
On 01/05/07, Daevid Vincent <daevid@daevid.com> 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']
True, but notice he's using it inside a heredoc string and the rules are slightly different for string parsing. http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing Whereas outside a string, $foo[myindex] will give you a notice and $foo['myindex'] is OK; Inside a string, $foo[myindex] will give you no notice and $foo['myindex'] will give you a parse error. The manual suggests that $foo[myindex] is treated the same inside a string as outside - if 'myindex' is defined as a constant then that is what's used as the index. This doesn't seem to be born out by reality. <?php error_reporting(E_ALL); $test = array(
         'FOO' => 'Bareword',
         'BAR' => 'Constant'
       );
define( 'FOO', 'BAR'); print "\$test[FOO]: FOO is interpreted as a $test[FOO]\n"; print "{\$test[FOO]}: FOO is interpreted as a {$test[FOO]}\n"; print "{\$test['FOO']}: FOO is interpreted as a {$test['FOO']}\n"; ?> $ php5 test.php $test[FOO]: FOO is interpreted as a Bareword {$test[FOO]}: FOO is interpreted as a Constant {$test['FOO']}: FOO is interpreted as a Bareword

« previous php.general (#254179) next »