String concatenation: why period?

This is a discussion on String concatenation: why period? within the PHP Language forums, part of the PHP Programming Forums category; Why did the designers of PHP decide to use period (".") as the string concatenation operator rater than the ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-21-2004
Jonathan
 
Posts: n/a
Default String concatenation: why period?

Why did the designers of PHP decide to use period (".") as the string
concatenation operator rater than the obviously more logical plus
("+")?

//JJ
Reply With Quote
  #2 (permalink)  
Old 08-21-2004
Andy Hassall
 
Posts: n/a
Default Re: String concatenation: why period?

On 20 Aug 2004 15:40:32 -0700, jonjo002@yahoo.com (Jonathan) wrote:

>Why did the designers of PHP decide to use period (".") as the string
>concatenation operator rater than the obviously more logical plus
>("+")?


Cos that's how Perl does it, and PHP was originally written in Perl?

It separates arithmetic operations from string operations; is it more logical
that "1"+"2" == "12", or 3? By picking a separate concatenation operator, you
remove the ambiguity and let you have both ways available.

"1"+"2" == int(3)
"1"."2" == string(2) "12"

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Reply With Quote
  #3 (permalink)  
Old 08-21-2004
Skeleton Man
 
Posts: n/a
Default Re: String concatenation: why period?

>Why did the designers of PHP decide to use period (".") as the string
>concatenation operator rater than the obviously more logical plus
>("+")?


More logical to me having the period.. but I come from a perl background
before I learned PHP..

Regards,
Chris


Reply With Quote
  #4 (permalink)  
Old 08-21-2004
Chung Leong
 
Posts: n/a
Default Re: String concatenation: why period?

"Andy Hassall" <andy@andyh.co.uk> wrote in message
news:o10di0dn8s7bt49gfhb1oj4ass6jpm3tm9@4ax.com...
> Cos that's how Perl does it, and PHP was originally written in Perl?


AFAIK, PHP has also been in C. Who here has used the original PHP/FI?



Reply With Quote
  #5 (permalink)  
Old 08-21-2004
Michael Austin
 
Posts: n/a
Default Re: String concatenation: why period?

Skeleton Man wrote:

>>Why did the designers of PHP decide to use period (".") as the string
>>concatenation operator rater than the obviously more logical plus
>>("+")?

>
>
> More logical to me having the period.. but I come from a perl background
> before I learned PHP..
>
> Regards,
> Chris
>
>


Originally PHP == Perl Hypertext Preprocessor. Later it was changed to PHP:
Hypertext Preprocessor. It was originally just a collection of Perl Scripts to
do "stuff" and was eventually formalized into it's own scripting language that
resembles it's Perl and C roots.

--
Michael Austin.
Consultant - Not Available.
Donations still welcomed. Http://www.firstdbasource.com/donations.html
:)
Reply With Quote
  #6 (permalink)  
Old 08-21-2004
Michael Austin
 
Posts: n/a
Default Re: String concatenation: why period?

Michael Austin wrote:

> Skeleton Man wrote:
>
>>> Why did the designers of PHP decide to use period (".") as the string
>>> concatenation operator rater than the obviously more logical plus
>>> ("+")?

>>
>>
>>
>> More logical to me having the period.. but I come from a perl background
>> before I learned PHP..
>>
>> Regards,
>> Chris
>>
>>


and if I had read all of the history, see: http://www.php.net/manual/en/history.php
it's ORIGINAL name was:
Personal Home Page Tools/Forms Interpreter. I had only heard the response I gave
earlier.

> Originally PHP == Perl Hypertext Preprocessor. Later it was changed to
> PHP: Hypertext Preprocessor. It was originally just a collection of
> Perl Scripts to do "stuff" and was eventually formalized into it's own
> scripting language that resembles it's Perl and C roots.
>




--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Reply With Quote
  #7 (permalink)  
Old 08-21-2004
Phil Roberts
 
Posts: n/a
Default Re: String concatenation: why period?

jonjo002@yahoo.com (Jonathan) emerged reluctantly from the curtain
and staggered drunkenly up to the mic. In a cracked and slurred
voice he muttered:

> Why did the designers of PHP decide to use period (".") as the
> string concatenation operator rater than the obviously more
> logical plus ("+")?
>
> //JJ


One of the major problems is that PHP, like Perl, allows arbitrary
typecasting between strings and numbers. This means that unless you
have specific operators for string concatenation and numeric
addition you're going to run into problems with variable typing.

For example:

echo "2" + "2";
echo 2 + 2;
echo 2 + "2";

All will produce the same result, but:

echo 2 . "2"; -> "22"
echo 2 . 2; -> "22"

Even though the numbers in the first and second example are
strings. PHP simply typecasts the strings to intergers before
performing the math. In the 4th and 5th examples PHP typecasts the
intergers to strings before concatenating them. In any language
with strict typing this would result in an error.

--
Phil Roberts | Deedle Doot Doo Dee Dee | http://www.flatnet.net/

I could be wrong here, You could be right
Please forgive me I have sinned - Not on your life
But that's how you want me, But I'll never fear thee
Why you and not me? Tell me Holy Man
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:55 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0