Why did the designers of PHP decide to use a full stop / period / “.” as the string
concatenation operator rather than the more usual plus symbol “+” ?
Is there any advantage to it, or any reason at all? Or did they just like to? :o)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
The most obvious reason would probably be that PHP inherits a lot of its syntax from Perl – and Perl uses a dot (
.) for string concatenation.But, we can delve deeper into it and figure out why this was implemented in Perl – the
+operator is most commonly used for mathematical equations – it’s only used for concatenation in languages in which the variable type can define the way in which the operator works (simple explanation, example is C#)^ As you can see, the
+operator is used both for concatenation and addition in C#.Perhaps the reasoning goes lower level and is due to the boolean algebra of logic gates –
+meansORin logic gates, whereas.is used as theANDoperator – which makes sense when it comes to string concatenation.It makes sense to have two separate operators, one for concatenation and one for addition – it’s just unfortunate that these two can be mixed up due to other languages.