The new PHP
The PHP language is experiencing a renaissance.PHP is transforming into a modern scripting language with helpful features like namespaces,traits,closures,and a builtin opcode cache.The modern PHP ecosystem is evolving,too.PHP developers rely less on monolithic frameworks and more on smaller specialized components.The Composer us from a frameworks is revolutionizing how we build PHP applications;it emancipates us from a frameworks`s walled garden and lets us mix and match interoperable PHP components best suited for our custom PHP applications.Component interoperability would not be possible without community standards proposed and curated by the PHP Framework Interop Group.
Modern PHP is your guide to the new PHP,and it will show you how to build and deploy amazing PHP applications using community standards,good practices,and interoperable components.
全新的PHP语言
PHP语言正在经历一场复兴,PHP是一种置入了众多优秀特性的现代脚本语言,如命名空间,多重继承,结束符,内置OPCODE缓存.PHP的生态系统也日趋完善,PHP开发者不需要过多的依赖完整的框架和专业组件,依赖管理工具Composer为我们创建PHP应用带来了革命性的变化,将我们从PHP框架的围栏中解放了出来,使我们可以为自己的自定义应用安装尽可能少的,易于维护和管理的PHP扩展组件,扩展组件的互用性不会脱离社区标准和PHP框架规范.
现代PHP将会带你认识全新的PHP语言,并且将会向您展示如何创建和部署标准,优雅,包含规范组件的PHP应用程序.
PAST
Before we explore modern PHP,it is important to understands PHP`s origin.PHP is an imterpreted server-side scripting language.this means you write PHP code,upload it to a web server,and execute it with an interpreter.PHP is typically used with a web server like Apache or nigix to server dynamic content.however,PHP can also be uesd to build powerful command-line application(just like bash,ruby,python,and so on).many PHP developers don`t realize this and miss out on a really exciting feature.not you,though.
过去
在探索现代PHP前,我们需要追溯一些重要的历史,PHP是一种服务器端的脚本语言,这意味着你需要将编写的PHP代码上传至服务器并且由编译器解释运行,通常使用阿帕奇或nginx为动态脚本提供服务,PHP同样可以像bash,ruby,python等语言一样,创建强大的命令行应用程序.很多PHP开发者并没有发挥出这些已有特性.
You can read the official PHP history at http://php.net/manual/zh/history.php . I won`t repeat what has already been said so well by Rasmus Lerdorf(the creator of PHP).what I will tell you is that PHP has a tumultuous past.PHP began as a collection of CGI scrips written by Rasmus Lerdorf to track visits to his online resume.Lerdorf named his set of CGI scripts “personal Hone Page Tools”.this early incarnation was completely different from the PHP we know today.Lerdorf`s early PHP tools were not a scripting language;they were tools that provided rudimentary variables and automatic form variable interpretation using an HTML embedded syntax.
你可以在(http://php.net/manual/zh/history.php)阅读官方撰写的PHP历史,我不必重复PHP作者Rasmus Lerdorf说”PHP已经很好”之类的句子,而是要告诉你PHP纷乱的历史.PHP最初只是Rasmus Lerdorf对CGI脚本的封装用于在线浏览他的简历.Lerdorf为这个CGI脚本命名为”个人首页工具”,这个早期的原型与现在的PHP太有不同,Lerdorf编写的早期PHP工具并不是一个脚本语言,而是提供基本变量和自动解析嵌入HTML变量的工具.
Between 1994 and 1998,PHP underwent numerous recisions and even received a few ground-up rewrites.andi gutmans and zeev suraski,two developers from tel aviv,joined force with Rasmus Lerdorf to transform PHP from a small collection of CGI tools into a full-fledged programming language with a more consistent syntax and basic support for object-oriented programming.they named their final product PHP3 and released it in 1998,the new PHP moniker was a departure from earlier names,and it is a recursive acronym for PHP:Hypertext preprocessor.PHP3 was the first version that most resembled the PHP,we know today.it provided superior extensibility to various databases,and APIs,PHP 3`s extensibility attracted many new developers to the project.by late 1998,PHP 3 was already installed on a staggering 10% of the world`s web servers.
在1994至1998之间,PHP承受了数不清的优化和对底层的修改,andi gumans和zeev suraski两名来自特拉维夫的开发者加入了Rasmus Lerdorf,为PHP从CGI小工具到一门完整成熟的,拥有稳定语法和初步支持对面向对象的程序设计语言做出了贡献.他们将最终的产品命名为PHP3并在1998年发布.PHP这个命名源自超文本预处理器( Professional Hypertext Preprocessor)首字母缩写.PHP3是最早的类似于现代PHP的版本,他为不同数据库和API提供了较好的可扩展性,正是因为PHP3良好的扩展性,吸引了众多开发者使用PHP进行应用开发,在1998年末,PHP3已经部署在全球10%的web服务器上.
Present
Today,the PHP language is quickly evolving and is supported by dozens of core team developers from around the world.development practice have changed,too.in the past,it was common practice to write a PHP file,upload it to a production server with FTP,and hope it worked.this is a terrible development strategy,but it was necessary due to a lack of viable local development environments.
如今
今天,在全世界众多核心团队的支持下,PHP得到了快速的发展,开发者的做法同样也发生了变化.过去,通常的作法是编写PHP代码,利用FTP上传至服务器然后希望程序能够正常运行.这是一种恐怖的方式,虽然很高效,但是迫切的需要本地开发环境.
Nowadays,we eschew FTP and use version control instead.version control software like git helps maintain an auditable code history that can be branched,forked,and merged.local development environments are identical to production servers thanks to virtualization tools like vagrant and provisioning tools like ansible,chef,and puppet.we leverage specialized PHP components with the composer dependency manager.our PHP code adheres to PSR`s fastCGI process manager behind a web server like nginx.and we increase application performance with an opcode cache.
如今,我们放弃了FTP转而使用版本控制工具,如GIT我们可以通过创建,克隆,合并分支,保持对代码的审计性与追溯性.借由虚拟化工具如vagrant和自动化运维工具ansible,chef,puppet我们可以保持本地环境与生产环境一致,借由依赖关系工具composer,我们可以轻松的管理各类PHP扩展组件,我们的PHP代码依附在PSR规范下的FastCGI进程管理器,运行在WEB服务器之后如nginx,我们还能通过opcode缓存进一步提高应用程序的性能.
Modern PHP encompasses many new pratices that may be unfamiliar to those of you new to PHP,or to those upgrading from older PHP versions,don`t feel overwhelmed,i`ll walk though each concept later in this book.
I`m also excited that PHP now has an official draft specification–something it lacked until 2014.
现代PHP包含许多新的特性,初次接触或者升级旧版本PHP时可能会给你代码一些不便,不过没有必要恐惧,在本书中我们会一一解释这些概念.
同样令人兴奋的是,PHP终于有了官方规范草案,这些在2014年之前是不存在的.
Sara golemon and facebook announced the first PHP specification draft at O`Reilly`s OSCON conference in 2014,you can read the official announcement on the PHP internals mailing list,and you can read the PHP specification on Github.
An official PHP language specification is becoming more important given the introduction of multiple competing PHP engines.the original PHP engine is the zend engine,a PHP interpreter written in C and introduced in PHP4.the zend engine was created by Rasmus Lerdorf,andi gutmans,and zeev suraski.today the zend engine is the zend company`s main contribution to the PHP community.however,there is now a second major PHP engine–the HipHop virtual machine from facebook.a language specification ensures that both engines maintain a baseline compatibility.
Sara golemon和facebook在2014年OSCON开源大会发布了第一份PHP规范草案, 你可以在PHP内部邮件和GITHUB列表阅读这份草案.
PHP官方规范引文包含了几种相互矛盾的PHP引擎,最初的PHP引擎是zend引擎,解释器由C语言编写并在PHP4中使用.zend引擎由Rasmus Lerdorf,gutmans,zeev suraski创建,现在是zend公司对社区的主要贡献.不过现在出现了第二种主要的PHP引擎–由facebook推出的HipHop虚拟机,PHP语言保持了对两种引擎的最基本的兼容性.
Future
The zend engine is improving at a rapid pacce with new features and improved performance.I attribute the zend engine`s improvements to its new competition,specifically facebook`s hiphop virtual machine and hack programming language.
Hack is a new programming language built on top of PHP,it introduces static typing,new data structure,and additional interfaces while maintaining backward compatibility with existing dynamically typed PHP code.hack is targeted at developers who appreciate PHP`s rapid development characteristics but need the predictability and stability from static type.
未来
因为facebook的hiphop虚拟机和hack语言的竞争关系,Zend引擎在添加新特性和提高性能上的步伐越来越快.
Hack语言是一门构造于PHP之上的新语言,他提出了静态类型,新的数据格式,添加了新的接口并保持对已有的PHP动态类型的兼容,hack的目标是让开发者认识到PHP的急剧发展带来的优异性能需要建立在可预测的静态类型的基础上.