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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
>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 |
|
|||
|
"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? |
|
|||
|
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 :) |
|
|||
|
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 :) |
|
|||
|
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 |