From: Ahmed Mohsen on
On 6/11/2010 11:43 PM, Daevid Vincent wrote:
>> -----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; ?>
>

Hey Daevid, does this form <?php echo 'The answer is '.$answer; ?>
improve anything in processing time or it's just for the sake of
readability?

--
Kind regards,
Ahmed Mohsen.
From: Simon J Welsh on

On 12/06/2010, at 8:43 AM, Daevid Vincent wrote:

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

If you're doing it like that, you may as well use:

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

and leverage sending echo multiple parameters rather than using string concatenation.

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e




From: Robert Cummings on
Simon J Welsh wrote:
> On 12/06/2010, at 8:43 AM, Daevid Vincent wrote:
>> 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; ?>
>
> If you're doing it like that, you may as well use:
>
> <?php echo 'The answer is', $answer; ?>

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

Fixed that for you :)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.
From: Paul M Foster on
On Fri, Jun 11, 2010 at 05:29:50PM -0400, tedd wrote:

<snip>

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

The issue, as I recall, is that for Python 3, they are changing print
(without parentheses) to require parentheses. This change alone (and
there are others like this in Python 3) will necessitate a *lot* of code
rewrites. Sometimes I wonder about Guido van Rossum.

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

I tend to do it the way Tedd does, but I'm rethinking this. I recently
had occasion to do a lot of programming in C and Python, and one thing
stood out at me: I can't recall another language which allows
interpolation of variables within strings (without significant diddling,
if at all). It caused me great difficulty because I'm so used to doing
this in PHP. I can convert from '.' to '+' (as in most languages) in my
mind, but embedding variables in strings was a harder habit to break. My
opinion is that the dot operator used this way was a mistake for
PHP. Not using the dot operator to mean "concatenate" would mean we
could use it to replace the accursed '->' for class/method selection.
And the plus operator is obviously a more natural fit for string
concatenation.

And yes, if you're going to use the dot operator, surround it with
spaces for readability.

Paul

--
Paul M. Foster
From: "Daevid Vincent" on
> -----Original Message-----
> From: Paul M Foster [mailto:paulf(a)quillandmouse.com]
> Sent: Saturday, June 12, 2010 10:40 PM
>
> this in PHP. I can convert from '.' to '+' (as in most
> languages) in my
> mind, but embedding variables in strings was a harder habit
> to break. My
> opinion is that the dot operator used this way was a mistake for
> PHP. Not using the dot operator to mean "concatenate" would mean we
> could use it to replace the accursed '->' for class/method selection.
> And the plus operator is obviously a more natural fit for string
> concatenation.
>
> And yes, if you're going to use the dot operator, surround it with
> spaces for readability.

Ironically, I believe that in the old days of PHP/FI the "+" was used
instead of "." -- to their defense, OOP wasn't even around then and so no
precedent had been set for the "." and I think they wanted to avoid
confusion with actual addition. I just remember having to go through and
re-work a bunch of code that broke b/c of this change.

But yes, I agree with you there. + should have stayed as the concat AND
addition, just like in JavaScript and other languages, and "." should have
been used instead of "->"

All of this I think could have been done AND maintain backwards
compatability with the use of some php.ini directives. Alternatively, I bet
some fancy regex scripts could also have been written that would migrate
"old" code to "new" code styles (I think the python guys did this for
"print")

*sigh*. It is what it is now. Ain't no going back from here. Like it or
lump it as they say.