From: tedd on
At 5:53 PM -0700 6/10/10, Daevid Vincent wrote:
>I use them ALL the time. MUCH cleaner IMHO than the alternatives.
>
>And *IF* someday it is ever depricated, it's trival to:
>
> s/<?=/<? echo/g
>
>Don't let 'em scare ya!


s/<?=/<?php echo/g

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
From: David Harkness on
On Fri, Jun 11, 2010 at 11:16 AM, Ashley Sheridan
<ash(a)ashleysheridan.co.uk>wrote:

> For <?= to work, the short_tags setting needs to be turned on I believe,
> which can cause issues when outputting the XML declaration line unless
> it's broken into two parts, which is messier than '<?php echo' IMHO.
>

Can you give an example of how this breaks? I don't see any problems with

<?= '<?xml blah blah ?>' ?>

unless you are trying to validate your PHP script as XML. Given that PHP is
*not* XML I don't know why you'd want to do that. But I've seen this
argument a few times while looking into this issue so maybe I'm just not
seeing the big picture.

David
From: "Daevid Vincent" on
> -----Original Message-----
> From: tedd [mailto:tedd.sperling(a)gmail.com]
>
> I believe, just because it can be done doesn't mean that it
> should be done.
>
> My practice is *never* to use <?=
>
> In fact, my practice is to not only use <?php echo, but to enclose
> the echo argument with a (), like:
>
> <?php echo("The answer is $answer");?>
>
> I am sure there will be some that think that my practice is an
> overkill, or not "good practice", but it's a good thing that we all
> have a choice. Make your choice to best serve how you want your code
> to look.

As per http://us3.php.net/echo

echo() is not actually a function (it is a language construct), so you are
not required to use parentheses with it. echo() (unlike some other language
constructs) does not behave like a function, so it cannot always be used in
the context of a function. Additionally, if you want to pass more than one
parameter to echo(), the parameters must not be enclosed within
parentheses.

So you might want to reconsider your coding practice/style here and use the
construct as designed or you might end up with a far worse scenario than
short-tags could ever provide. Something more along the Python "print"
debacle.

Also, for the love of God, please don't embed a variable into a literal
string and use preprocessing.

Do it like so:

<?php echo 'The answer is '.$answer; ?>

From: "Daevid Vincent" on


> -----Original Message-----
> From: David Harkness [mailto:david.h(a)highgearmedia.com]
> Sent: Friday, June 11, 2010 1:13 PM
> To: PHP General
> Subject: Re: [PHP] is <?= good?
>
> On Fri, Jun 11, 2010 at 11:16 AM, Ashley Sheridan
> <ash(a)ashleysheridan.co.uk>wrote:
>
> > For <?= to work, the short_tags setting needs to be turned
> on I believe,
> > which can cause issues when outputting the XML declaration
> line unless
> > it's broken into two parts, which is messier than '<?php echo' IMHO.
> >
>
> Can you give an example of how this breaks? I don't see any
> problems with
>
> <?= '<?xml blah blah ?>' ?>
>
> unless you are trying to validate your PHP script as XML.
> Given that PHP is
> *not* XML I don't know why you'd want to do that. But I've seen this
> argument a few times while looking into this issue so maybe
> I'm just not
> seeing the big picture.

....and even *IF* it did break for that ONE instance, then simply do as I do
in my xml_header.inc.php file:

header( "Content-type: text/xml" );
print "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";

Problem solved.

EVERY other tag in an XML document is just straight up "html" like:

<foo>bar</foo>

There are no other <?xml tags or anything to worry about.

Again the whole XML argument seems to be exaggerated.

From: tedd on
At 1:43 PM -0700 6/11/10, Daevid Vincent wrote:
> > -----Original Message-----
> > From: tedd [mailto:tedd.sperling(a)gmail.com]
> > In fact, my practice is to not only use <?php echo, but to enclose
>> the echo argument with a (), like:
>>
> > <?php echo("The answer is $answer");?>
>>
>> I am sure there will be some that think that my practice is an
>> overkill, or not "good practice", but it's a good thing that we all
>> have a choice. Make your choice to best serve how you want your code
>> to look.
>
>As per http://us3.php.net/echo
>
>echo() is not actually a function (it is a language construct), so you are
>not required to use parentheses with it. echo() (unlike some other language
>constructs) does not behave like a function, so it cannot always be used in
>the context of a function. Additionally, if you want to pass more than one
>parameter to echo(), the parameters must not be enclosed within
>parentheses.
>
>So you might want to reconsider your coding practice/style here and use the
>construct as designed or you might end up with a far worse scenario than
>short-tags could ever provide. Something more along the Python "print"
>debacle.
>
>Also, for the love of God, please don't embed a variable into a literal
>string and use preprocessing.
>
>Do it like so:
>
><?php echo 'The answer is '.$answer; ?>

Daevid:

I'm aware that echo is a language construct and does not require the
(). However, please note the reference you provided, namely:

http://us3.php.net/echo

They use "echo()" to describe the construct -- so, if they can use
it, then I figure I'm in good company.

I also practice using () because it is easier for *me* to read,
understand, and document my work. You are free to do as you want.

As for the Python "print" problem, I don't do Python -- so, it can
win the lottery, or die, I don't care.

As for "don't embed a variable into a literal string and use
preprocessing", as I said above, I often do this:

<?php echo("The answer is $answer");?>

and find no problems whatsoever in doing so.

However, I wouldn't do this:

<?php echo 'The answer is '.$answer; ?>

OR, I would place a space before/after the . (i.e., 'The answer is '
.. $answer). However, I don't like doing that because I also program
in other languages, which use the dot operator differently.

My experience has shown me that most, if not all, languages are
merging -- as such, I think the dot operator is more established as
something other than just an operation to combine strings.

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com