Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3489338
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:23:00+00:00 2026-05-18T11:23:00+00:00

In PHP, the string operator dot (.) is used to concatenate strings. For example:

  • 0

In PHP, the string operator dot (.) is used to concatenate strings. For example:

$msg = "Hello there, " . $yourName;

The dot operator always seems to confuse people (myself included) the first time they see it, especially since when you use it to concatenate two strings, the operation does not throw an error, but just "silently" fails. It is also a common mistake when switching between PHP and other languages such as JavaScript, Python, etc. that do not use this operator.

Why does the language use the dot (.) operator instead of a more widely accepted operator, such as plus (+)? Are there any historical reasons you can point to as to why this operator was selected? Is it just because the dot can cast other variable types to string? For example:

echo 1 . 2;                // Prints the string "12"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:23:01+00:00Added an answer on May 18, 2026 at 11:23 am

    I think it is a good idea to have a different operator, because dot and plus do completely different things.

    What does "a string" + "another string"; actually mean, from a non specific language point of view?

    Does it mean

    • Add the numerical value of the two strings, or,
    • concatenate the two strings

    You would assume it is the second, but a plus sign is used for numerical addition in all cases except Strings. Why?

    Also, from a loosely typed point of view (which PHP is), a php script

    $myvar = 1;
    $myvar2 = 2;
    
    // would we expect a concatenation or addition?
    $concat = $myvar + $myvar2;
    

    The dot notation therefore specifies that it is clearly used for concatenation.

    It is not that it is confusing, it is that it is not intuitive because all the other languages do it in a different way. And, is this a good reason to follow the trend? Doing things the way they are always done, is not always the right way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In other languages you can use strings as keys - PHP: $array['string'] = 50;
My php is weak and I'm trying to change this string: http://www.example.com/backend.php?/c=crud&m=index&t=care ^ to
Possible Duplicate: Pass a PHP string to a Javascript variable (and escape newlines) I
How do I convert the value of a PHP variable to string? I was
<?php function toconv(string) { $gogo = array(a => b,cd => e); $string = str_replace(
PHP has a great function called htmlspecialcharacters() where you pass it a string and
PHP has the habit of evaluating (int)0 and (string)0 as empty when using the
In PHP, a string enclosed in double quotes will be parsed for variables to
I have a string encrypted in PHP that I would like to decrypt in
Say i have this PHP code: $FooBar = a string; i then need a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.