search
HomeBackend DevelopmentPHP Tutorial从ZendEngine2.0的设计蓝图看PHP的将来


  一些杂谈
  首先是本文写作的初衷。我拿到关于Zend Engine 2.0的设计蓝图文档已经有一段时间了(现在大家也可以去参考资料中的地址下载回来看看),看完之后就有了写一篇评论的冲动--因为根据文档的描述下一代的PHP将是一种更符合现有面向对象开发习惯的语言,至少是被更多的赋予了面向对象特性。但是随之带来的问题就是对于PHP这样一个以Web快速开发为初始目标的语言是否值得将自己修饰得面面俱到?这个问题看来是需要一些评论文章来讨论的,我也很愿意提出自己的观点。但是后来一些繁忙的事情就将这个冲动一点点又打回了肚里,直到最近一段时间又想起,于是再拜读几遍设计蓝图文档,遂有此文。(刚拿到这份英文文档的时候我还有将这份设计蓝图文档翻译到中文的打算,但是考虑到一是并非最终蓝图,二是大家都应该培养直接阅读原文的习惯,三是翻译总是不可避免会带来一些晦涩的地方,于是暂时作罢。不过写成此文的时候,还是决定"冒险"翻译一次,不能准确达意之处还请各位不吝指正。)
  
  其次是对本文讨论焦点的解释--在这篇评论中我将主要针对将来的PHP中得以大大加强的面向对象特性进行评述。如果你是PHP的开发者,那么我猜想你应该了解一些PHP语言中的面向对象特性;但是由于一般PHP用于"极端快速开发环境"(这是我自己生造出的一个词语,表示进行一些以客户为导向的网站开发的情况,特点就是工期非常短且客户要求不甚明确),所以真正大量使用其对象特性的开发者以及开发项目并不是很多;另外,现有PHP对象模型相对C++和Java的弱势,也限制了这方面特性的使用。不过在PHP的将来版本中,修改重点就在于语言中的面向对象模型,完善现有版本中许多不良的特性并加入其他特性。因此讨论PHP的未来面貌就集中在讨论PHP的面向对象特性方面。
  
  好了,让我们步入正题,看看Zend Engine 2.0的新特性。
  
  归纳Zend Engine 2.0设计蓝图(草稿)
  从设计蓝图(草稿)中可以非常清楚的看出下一代Zend Engine是以新的面向对象模型为基础的。如果你曾经使用过现有PHP 4的面向对象特性,那么也许会在找到一点点Java或者C++的感觉的同时觉得有些别扭--不但是在面向对象语法的匮乏上,而且有时会得到意想不到的运行结果--这一切都是因为在现有的支持PHP 4的Zend Engine 1.0中不那么优雅的面向对象模型造成的。
  
  简单说来,下一代的Zend Engine将向Java靠拢,大量借鉴其面向对象模式。从改进特性的类型来看,应该可以分为三类:第一类是对现有面向对象模型的改进和加强,其中包括对构建器和析构器的定义,增加的私有成员变量、静态成员变量、多重继承、过载等面向对象特性;第二类是对于控制流程的修改和增删,比如增加了形如try/catch/throw违例处理机制;第三类是关于函数的修改和增删,比如对于字符串偏移量的增加函数。(对于每一类改进的详细情况,可以查阅参考资料中所列文档。)由此可以看出,通过第一类和第二类的改进,PHP正在逐步将自己改良成一种具有面向对象特征的语言。
  
  不过问题恰恰就产生于此:
  从积极的方面来说,如今的编程世界中更加欢迎具有面向对象特征的语言(即使语言本身并不构建于面向对象基础之上,也可以通过增加定义的对象等手段使得该语言不至于落在潮流之后)--从这一意义上说,Zend Engine 2.0使得PHP对面向对象的支持将从现在的试探性接触转变为将来的全面拥护,看来更加符合编程语言发展的潮流;另外,在构建企业级应用(这也是PHP现在经常被人指责之处)之时,采用面向对象的方法建模和实现已经是事实上的标准,而PHP的这一改进也许会迎合这一需要,解决语言自身在这方面的薄弱之处。
  从消极的方面来说,为开发者奉献一个更加类似Java的新版PHP似乎没有什么意义。PHP被广泛应用的原因,除了源码公开和跨平台等之外,适应互联网站构建的简单、快速的web编程(在现在的程序开发中占有很大的比重)特点恐怕也是重要的一点。极短的学习时间、友好的语言风格(特别是如果你对C比较熟悉)和大量扩充类库函数,足以证明其强大;但是如果将这样的语言的下一版本改造成类似面向对象的语言,不但会使原有的大量开发者在短时间内无所适从,而且非常不利于吸引新的开发者加入--既然有Java这样的语言,何必去学习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
Explain the concept of a PHP session in simple terms.Explain the concept of a PHP session in simple terms.Apr 26, 2025 am 12:09 AM

PHPsessionstrackuserdataacrossmultiplepagerequestsusingauniqueIDstoredinacookie.Here'showtomanagethemeffectively:1)Startasessionwithsession_start()andstoredatain$_SESSION.2)RegeneratethesessionIDafterloginwithsession_regenerate_id(true)topreventsessi

How do you loop through all the values stored in a PHP session?How do you loop through all the values stored in a PHP session?Apr 26, 2025 am 12:06 AM

In PHP, iterating through session data can be achieved through the following steps: 1. Start the session using session_start(). 2. Iterate through foreach loop through all key-value pairs in the $_SESSION array. 3. When processing complex data structures, use is_array() or is_object() functions and use print_r() to output detailed information. 4. When optimizing traversal, paging can be used to avoid processing large amounts of data at one time. This will help you manage and use PHP session data more efficiently in your actual project.

Explain how to use sessions for user authentication.Explain how to use sessions for user authentication.Apr 26, 2025 am 12:04 AM

The session realizes user authentication through the server-side state management mechanism. 1) Session creation and generation of unique IDs, 2) IDs are passed through cookies, 3) Server stores and accesses session data through IDs, 4) User authentication and status management are realized, improving application security and user experience.

Give an example of how to store a user's name in a PHP session.Give an example of how to store a user's name in a PHP session.Apr 26, 2025 am 12:03 AM

Tostoreauser'snameinaPHPsession,startthesessionwithsession_start(),thenassignthenameto$_SESSION['username'].1)Usesession_start()toinitializethesession.2)Assigntheuser'snameto$_SESSION['username'].Thisallowsyoutoaccessthenameacrossmultiplepages,enhanc

What are some common problems that can cause PHP sessions to fail?What are some common problems that can cause PHP sessions to fail?Apr 25, 2025 am 12:16 AM

Reasons for PHPSession failure include configuration errors, cookie issues, and session expiration. 1. Configuration error: Check and set the correct session.save_path. 2.Cookie problem: Make sure the cookie is set correctly. 3.Session expires: Adjust session.gc_maxlifetime value to extend session time.

How do you debug session-related issues in PHP?How do you debug session-related issues in PHP?Apr 25, 2025 am 12:12 AM

Methods to debug session problems in PHP include: 1. Check whether the session is started correctly; 2. Verify the delivery of the session ID; 3. Check the storage and reading of session data; 4. Check the server configuration. By outputting session ID and data, viewing session file content, etc., you can effectively diagnose and solve session-related problems.

What happens if session_start() is called multiple times?What happens if session_start() is called multiple times?Apr 25, 2025 am 12:06 AM

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

How do you configure the session lifetime in PHP?How do you configure the session lifetime in PHP?Apr 25, 2025 am 12:05 AM

Configuring the session lifecycle in PHP can be achieved by setting session.gc_maxlifetime and session.cookie_lifetime. 1) session.gc_maxlifetime controls the survival time of server-side session data, 2) session.cookie_lifetime controls the life cycle of client cookies. When set to 0, the cookie expires when the browser is closed.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.