The plus sign is not as "widely accepted" as you would imagine for concatenating strings. There are a lot of languages which don't use it, including Perl and C, and since these are which are where PHP's roots lie, it makes sense for PHP to follow suit. Many languages don't even have an operator for it; you'd have to use a concat()
function.
PHP is weakly typed, and will do implicit type conversion when it sees the plus sign or a dot. This means that if you do $x = "45 inches" + "20 inches";
, PHP will set $x
to 65
. If you use the dot concatenation operator, the result will clearly be very different. The same applies if you have $y = 5 . 10;
. This will give you 510
, but change it to a plus sign and you get a completely different result.
Also, thinking logically, the opposite of a plus is a minus. But that doesn't map so easily to concatenation. (I have seen one language that tried it, but it really didn't make much sense)
Your preference for the plus sign as a concatenator is purely down to a resistance to change when learning a new language (quite a common thing - I know a few people who initially hated Python because it lacks curly braces!)
As someone who's programmed for a long time using a lot of languages, I can tell you that I much prefer to have an unambiguous concatenation operator. Using the same operator for addition and concatenation in a loosely-typed language is asking for trouble; in fact, I would say it's one of Javascript's biggest flaws (and this is coming from someone who in general is a fan of Javascript).
Python is stronly-typed, which means that it can get away with using the plus sign as the addition and concatenation operator because it forces you to work with the same type; you can't add an integer to a string in Python; if you need to then you have to explicitly cast your types, so there's no ambiguity, at least not to the compiler.
There is, however, still the ambiguity for the reader - it may not immediately be obvious from reading what was meant by any given plus sign in the code. It's easier in Python to work it out, but personally I'd still prefer to have an unambiguous operator. But that is just a personal preference; if I'm working with Python, Javascript or Visual Basic then I have to work to their rules.