Home  >  Article  >  Backend Development  >  php为什么弄点号连接字符串?

php为什么弄点号连接字符串?

WBOY
WBOYOriginal
2016-06-17 08:31:36944browse

我知道的大部分语言都是加号来连接字符串的。

回复内容:

对于像PHP、JS、Python 这种弱类型来说,+既是数字的相加,也是字符串的连接,问题来了:JS中 var a = 1+1; var a="1"+1; var a = "1"+"1"; 这些结果a是多少?是2还是11?你可能要花几分钟去思考或查资料。
但PHP不用思考就知道全都是1+1=2啊这么简单,因为PHP里面点号才是字符串连接。
再问一个为什么JS不能设计成用点号作字符串连接?因为对象。JS里面是用点号调用对象属性和方法,用同一个就会矛盾。PHP里面用横线箭头,看似很蠢,实则避免了各种混乱,大智若愚啊。 为什么Python在新建实例的时候不用new 呢?

为什么C++在声明字符串的时候不能用单引号呢?

为什么JAVA要用import而不用include呢?

为什么object C不用interface呢?

为什么C++的继承要用:不用extends呢?

为什么要问这种问题呢? php 的点连接字符串和美元符号变量声明来自于 perl。

而在 php 出现之前,绝大部分 web cgi 程序不是直接用 c 就是用 perl 写的。 php是世界上最好的语言,
特立独行也没什么大不了的,
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn