“最好的语言”PHP过时了吗?
<div style="color: black; text-align: left; margin-bottom: 10px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">晓查 乾明 发自 凹非寺 </p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">量子位 <span style="color: black;">报告</span> | 公众号 QbitAI</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">当下,<span style="color: black;">倘若</span>你打开搜索引擎,搜索关键词“PHP过时”,能找到714万个<span style="color: black;">关联</span>结果。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/56630d525e8d4b968957a7387776d514~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729837341&x-signature=y9OG1mBYam1HDaeiG1ufysNr7%2B4%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这些结果之中,不乏有2016年、2018年的结果,说PHP<span style="color: black;">已然</span>过时了。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">现已2019年,这个曾经自<span style="color: black;">叫作</span>为“世界上最好的语言”PHP,<span style="color: black;">状况</span><span style="color: black;">怎样</span>?</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">一位名叫Brent的程序员小哥,写了一篇博客<span style="color: black;">文案</span>,介绍了PHP在2019年的<span style="color: black;">状况</span>。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">他说,<span style="color: black;">此刻</span>的PHP每年都会积极<span style="color: black;">研发</span>新版本,从2004年发布PHP 5<span style="color: black;">败兴</span>性能<span style="color: black;">已然</span><span style="color: black;">提高</span>了两到三倍。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">况且</span>,有很活跃的生态系统,里面有<span style="color: black;">各样</span>各样的框架、包和平台。过去几年,PHP<span style="color: black;">亦</span>添了<span style="color: black;">非常多</span>新功能,语言<span style="color: black;">持续</span>发展等等。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">他<span style="color: black;">期盼</span>,<span style="color: black;">大众</span>都放弃偏见,重新认识下<span style="color: black;">此刻</span>的PHP。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/a7096d09022043849f5f0478e0cecbf2~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729837341&x-signature=1u0STY0LcsD5CCL9txubkqGi3c8%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">博客<span style="color: black;">文案</span>被po到HackerNews上之后,半天就有700多热度,<span style="color: black;">导致</span>近400条讨论。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">有人<span style="color: black;">暗示</span>,自己还是不<span style="color: black;">爱好</span>PHP的代码和架构,<span style="color: black;">由于</span>代码很难看,还是围绕着静态<span style="color: black;">办法</span>构建的,<span style="color: black;">不易</span>阅读。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">亦</span>有人给点了赞,说从生态系统、性能、语言本身上来看,PHP这几年的发展的确不错。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">那样</span>,PHP<span style="color: black;">此刻</span>到底怎样呢?来<span style="color: black;">一块</span><span style="color: black;">瞧瞧</span>。</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><strong style="color: blue;">PHP的性能:7.0版本<span style="color: black;">提高</span>两到三倍</strong></h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">此刻</span>,PHP<span style="color: black;">已然</span>更新到了7.3版本,2019年底将<span style="color: black;">会跟新</span>7.4版本,之后会升级到8.0版本。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">小哥<span style="color: black;">暗示</span>,PHP5.0版本在2004年发布的时候,它的性能就<span style="color: black;">已然</span>达到了平均水平。在升级到7.0版本的时候,又从头<span style="color: black;">起始</span>重写了一遍核心部分,运行WordPress 5.0时,性能<span style="color: black;">提高</span>了两到三倍。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/f0b728b3bae64016a6822087cbac41dc~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729837341&x-signature=rOvVJH5QKH5jKZe7AF7qeDrdf84%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在Web应用程序中,PHP与其他语言<span style="color: black;">亦</span>有可比性,在某些<span style="color: black;">状况</span>下性能表现还更好。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">虽然与C和Rust相比,PHP还是略逊一筹,但比Rails或Django要好得多,性能<span style="color: black;">亦</span>比得上ExpressJS。</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><strong style="color: blue;">框架和生态系统:<span style="color: black;">不仅</span>是WordPress</strong></h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在HackerNews的讨论中,<span style="color: black;">非常多</span>人都<span style="color: black;">说到</span>,<span style="color: black;">由于</span>WordPress的存在才让PHP有了些存在感。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">但小哥在博客中说,WordPress绝<span style="color: black;">不可</span><span style="color: black;">表率</span>PHP当前的生态系统。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">通常</span><span style="color: black;">来讲</span>,PHP中有两个<span style="color: black;">重点</span>的Web应用程序框架,分别是Symfony和Laravel。<span style="color: black;">此刻</span><span style="color: black;">运用</span>PHP做<span style="color: black;">研发</span>,基本上都会<span style="color: black;">选取</span>其中的一个。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这两个框架<span style="color: black;">背面</span>,都有一个庞大的包和<span style="color: black;">制品</span>生态系统,从管理面板和CRM到独立软件包,分析工具,支付集成等等。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">虽然这些框架适用于<span style="color: black;">实质</span><span style="color: black;">研发</span>,但<span style="color: black;">倘若</span>只需要进行内容管理,WordPress和CraftCMS是更好的<span style="color: black;">选取</span>,<span style="color: black;">况且</span>它们<span style="color: black;">亦</span>会进一步改进。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">另外</span>,衡量PHP生态系统当前状态的一种<span style="color: black;">办法</span>是看Packagist中的<span style="color: black;">状况</span>,这是PHP的<span style="color: black;">重点</span>软件包的存储库。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/e15da3e579ed41a6ac12c2d35b1874cf~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729837341&x-signature=mwjejDGdxinfLGB7nCbutqo8S4Q%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP<span style="color: black;">重点</span>软件包近年来已呈指数级增长,<span style="color: black;">每日</span>下载量达到2500万次。这足以证明,PHP生态系统<span style="color: black;">已然</span>远非昔日可比。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">除了应用程序框架和CMS之外,过去几年PHP中的异步框架<span style="color: black;">亦</span><span style="color: black;">起始</span>兴起,<span style="color: black;">例如</span>Swoole、Amp和ReactPHP等等,都是用PHP或其他语言编写的框架和服务器,能够让用户运行真正的异步PHP。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">此刻</span>, PHP<span style="color: black;">已然</span>进入了异步世界,像WebSocket和<span style="color: black;">拥有</span><span style="color: black;">海量</span>输入输出的应用程序之类的东西,<span style="color: black;">已然</span><span style="color: black;">起始</span>与PHP世界<span style="color: black;">关联</span>了。</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><strong style="color: blue;">语言本身</strong></h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">尽管async和await<span style="color: black;">此刻</span>还不可用,但在过去的几年里,PHP语言本身<span style="color: black;">已然</span>做了<span style="color: black;">非常多</span>改进。下面是一个不完全的PHP新特性列表:</p>短闭包Null合并运算符Traits代码复用机制类型化属性展开运算符JIT编译器<span style="color: black;">外边</span>函数接口匿名类返回类型声明现代加密库生成器<span style="color: black;">更加多</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">当谈到PHP语言特性的时候,让<span style="color: black;">咱们</span><span style="color: black;">亦</span>来<span style="color: black;">瞧瞧</span>今天PHP语言是<span style="color: black;">怎样</span>发展的。PHP有一个活跃的志愿者核心团队推动语言的发展,向社区征求意见(RFC,Request for Comments)。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">接下来,这些RFC在“内部”邮件列表中讨论,<span style="color: black;">亦</span><span style="color: black;">能够</span>在线浏览。在添加新的功能之前,必须进行投票。<span style="color: black;">仅有</span><span style="color: black;">最少</span>占2/3<span style="color: black;">都数</span>的RFC才被<span style="color: black;">准许</span>进入核心。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/91a5383534954fcba8901cc4e2f18955~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729837341&x-signature=U%2BaaYfegvTQOf3n1FQhV%2BpmdSpo%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">大<span style="color: black;">大概</span>100人<span style="color: black;">准许</span>参与投票。核心团队的成员当然有权投票,<span style="color: black;">由于</span><span style="color: black;">她们</span>必须<span style="color: black;">守护</span>代码<span style="color: black;">基本</span>。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">除此之外,还有一群人是从PHP社区中单独挑选出来的。这些人<span style="color: black;">包含</span>PHP文档的<span style="color: black;">守护</span>者,<span style="color: black;">全部</span>PHP项目的贡献者,以及PHP社区中杰出的<span style="color: black;">研发</span>人员。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">虽然大部分核心<span style="color: black;">研发</span>是在自愿的<span style="color: black;">基本</span>上完成的,<span style="color: black;">然则</span>核心PHP<span style="color: black;">研发</span>人员之一Nikita Popov<span style="color: black;">近期</span>加入了软件<span style="color: black;">机构</span>JetBrains,全职从事编程语言工作。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">另一个例子是<span style="color: black;">近期</span>决定投资Zend框架的Linux基金会。像<span style="color: black;">这般</span>的雇佣方式和收购<span style="color: black;">保证</span>了PHP<span style="color: black;">将来</span>发展的稳定性。</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><strong style="color: blue;">静态分析工具</strong></h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">过去几年里,围绕PHP本身的工具<span style="color: black;">已然</span>有所<span style="color: black;">增多</span>,<span style="color: black;">例如</span>由Vimeo<span style="color: black;">研发</span>的静态分析工具Psalm等等。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这些工具能够对你的PHP代码进行静态分析,并报告其中<span style="color: black;">显现</span>的错误以及可能会<span style="color: black;">显现</span>的错误。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/6f5c1291a2ac4a719f58b5d3ceed586d~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729837341&x-signature=LnUH6lY891xjWBLYjxrstReBBUA%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">尽管PHP还<span style="color: black;">无</span>被编译,不<span style="color: black;">准许</span><span style="color: black;">运用</span>自定义语法,但在某种程度上,它们<span style="color: black;">供给</span>的功能能够媲美TypeScript。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这<span style="color: black;">寓意</span>着,<span style="color: black;">此刻</span>的PHP<span style="color: black;">研发</span>者要依赖文档块。但PHP的原始创建者Rasmus Lerdorf,<span style="color: black;">已然</span><span style="color: black;">知道</span><span style="color: black;">说到</span>了要在内核中添加静态分析引擎。这一想法的<span style="color: black;">潜能</span>很大,但任务<span style="color: black;">一样</span>艰巨。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在传输方面,受到JavaScript社区的启发,PHP<span style="color: black;">研发</span>者社区<span style="color: black;">已然</span>在<span style="color: black;">奋斗</span>的拓展PHP语法。<span style="color: black;">例如</span>一个名为Pre的项目,<span style="color: black;">能够</span>把新的PHP语法转换成普通的PHP代码。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这个想法虽然<span style="color: black;">已然</span>在JavaScript世界中得到了证明,<span style="color: black;">然则</span><span style="color: black;">仅有</span>在<span style="color: black;">供给</span>了适当的集成<span style="color: black;">研发</span>环境和静态分析支持的<span style="color: black;">状况</span>下,它<span style="color: black;">才可</span>在PHP中发挥<span style="color: black;">功效</span>。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">尽管这是一个非常有趣的想法,<span style="color: black;">然则</span>在能够<span style="color: black;">叫作</span>之为“主流”之前,它还有很长的路要走。</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><strong style="color: blue;">PHP<span style="color: black;">已然</span>过时了吗?</strong></h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">再次把<span style="color: black;">专题</span>回到开头提出的问题上,PHP<span style="color: black;">已然</span>过时了吗?</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">除了上面的<span style="color: black;">有些</span>动态,还有一份报告<span style="color: black;">能够</span>参考。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">去年10月,GitHub发布2018年的年度报告。在热门编程语言中,PHP排名第四。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/7b4e1f2b5bb84afe8952e6d8a88da35e~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729837341&x-signature=mA8ykHVtenQFcii%2B6ip0r6KyoMA%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">虽然比不上JavaScript、Java,后来又被Python超过,但依旧比C++、C#等语言热度要高。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">— <strong style="color: blue;">完</strong> —</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">诚挚招聘</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">量子位正在招募编辑/记者,工作地点在北京中关村。期待有才气、有热情的<span style="color: black;">朋友</span>加入<span style="color: black;">咱们</span>!<span style="color: black;">关联</span>细节,请在量子位公众号(QbitAI)对话界面,回复“招聘”两个字。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">量子位 QbitAI · 头条号签约作者</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">վᴗ ի <span style="color: black;">跟踪</span>AI技术和<span style="color: black;">制品</span>新动态</p>
</div>
交流如星光璀璨,点亮思想夜空。 哈哈、笑死我了、太搞笑了吧等。
页:
[1]