Why a full stop, “.” and not a plus symbol, “+”, for string concatenation in PHP?

前端 未结 12 1628
暖寄归人
暖寄归人 2020-12-09 01:54

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

12条回答
  •  孤城傲影
    2020-12-09 02:20

    The use of the dot as string concatenation operator in PHP probably dates back to Perl. Remember that PHP once was nothing more than a bunch of Perl scripts.

    Also it makes sense to have distinct string concatenation and addition operators, especially in weakly-typed languages. There are enough pitfalls in PHP already to shoot yourself in the foot, you don't need to add another one.

提交回复
热议问题