String concatenation: why period?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jonathan

    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
  • Andy Hassall

    #2
    Re: String concatenation: why period?

    On 20 Aug 2004 15:40:32 -0700, jonjo002@yahoo. com (Jonathan) wrote:
    [color=blue]
    >Why did the designers of PHP decide to use period (".") as the string
    >concatenatio n operator rater than the obviously more logical plus
    >("+")?[/color]

    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.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • Skeleton Man

      #3
      Re: String concatenation: why period?

      >Why did the designers of PHP decide to use period (".") as the string[color=blue]
      >concatenatio n operator rater than the obviously more logical plus
      >("+")?[/color]

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

      Regards,
      Chris


      Comment

      • Chung Leong

        #4
        Re: String concatenation: why period?

        "Andy Hassall" <andy@andyh.co. uk> wrote in message
        news:o10di0dn8s 7bt49gfhb1oj4as s6jpm3tm9@4ax.c om...[color=blue]
        > Cos that's how Perl does it, and PHP was originally written in Perl?[/color]

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



        Comment

        • Michael Austin

          #5
          Re: String concatenation: why period?

          Skeleton Man wrote:
          [color=blue][color=green]
          >>Why did the designers of PHP decide to use period (".") as the string
          >>concatenati on operator rater than the obviously more logical plus
          >>("+")?[/color]
          >
          >
          > More logical to me having the period.. but I come from a perl background
          > before I learned PHP..
          >
          > Regards,
          > Chris
          >
          >[/color]

          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
          :)

          Comment

          • Michael Austin

            #6
            Re: String concatenation: why period?

            Michael Austin wrote:
            [color=blue]
            > Skeleton Man wrote:
            >[color=green][color=darkred]
            >>> Why did the designers of PHP decide to use period (".") as the string
            >>> concatenation operator rater than the obviously more logical plus
            >>> ("+")?[/color]
            >>
            >>
            >>
            >> More logical to me having the period.. but I come from a perl background
            >> before I learned PHP..
            >>
            >> Regards,
            >> Chris
            >>
            >>[/color][/color]

            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.
            [color=blue]
            > 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.
            >[/color]



            --
            Michael Austin.
            Consultant - Available.
            Donations welcomed. Http://www.firstdbasource.com/donations.html
            :)

            Comment

            • Phil Roberts

              #7
              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:
              [color=blue]
              > Why did the designers of PHP decide to use period (".") as the
              > string concatenation operator rater than the obviously more
              > logical plus ("+")?
              >
              > //JJ[/color]

              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

              Comment

              Working...