search
HomeBackend DevelopmentPHP TutorialDetailed analysis: About PHP event-driven issues_PHP tutorial

Detailed analysis: About PHP event-driven issues_PHP tutorial

Jul 13, 2016 pm 05:36 PM
phpeventaboutCanclientyesserverconceptofendparsedetailedthisquestiondrive

事件驱动这个概念是广义的。可以在客户端,也可以在服务器端。

在WEB应用上,在客户端的事件是基于JS或是插件或是JAVAAPPLET之类的东西,基本上如果是插件或是JAVAAPPLET的话,就不属于 HTML的范畴了,而真正必须用到JS的场合其实并不多,最多就是FORM的提交或是链接点击之类的基本操作,因此谈论事件无太大意义。

事件驱动真正的意义并不在于可视化编程,而在于它的概念,就象OO一样。事件驱动其实是OO的一个延伸,它的最初原型是消息机制。但是事件驱动把消息封装成了一个可调用的函数,有些类似于API中的回调函数,你自己可以定义这些函数执行的内容。而可视化编程则把这些函数独立出来,定义好参数(多数是现成的对象),让你自己写代码并运用这些参数(其实是用这些对象)做一些事情。

所以,PHP有事件驱动是完全可能的,主要在于框架的设计。而要做成VB之类所谓的可视化事件驱动,则必须要有配套的集成开发环境,包括页面设计,事件编码,编译转码之类的一系列功能才行。其实象点NET这样的事件驱动,只不过是把一些常用的WEB元素或控件,如按钮、文本框之类的东西封装了一下,让你有个可视化的界面可以设计一下,当它编译之后,仍然是之类的文本,只是把你的事件代码转为了JS或是服务器端代码而已。而PHP主要是由于IDE不够丰富,而且也没有预编译机制,所以最后提交的代码还是最终的PHP代码,而不是点NET的资源代码与事件代码的混合体(一般是符合XML规范的ASP文档,包含了非标准的HTML代码)。故此PHP还无法达到大家心目中狭义的所谓事件驱动编程,但其实是完全可以没有问题的。

如果大家感兴趣,不妨到www.php.net官方主页去看一下一位中国哥们(Qiang Xue)写的一套基于事件驱动的PHP框架PRADO,这个还是获得高票当选的最佳,强烈推荐!请参考http://www.zend.com/php5/contest,你看了他的源代码后就会理解PHP的事件驱动是怎么回事。但我认为,在这上面,由于PHP无预编译机制,而且过度依赖OO(虽然是用PHP5写的代码),造成这个框架有些庞大,且使用比较复杂,可扩展性也不是很好。不过,其中的理念非常之好,有些想法还解决了困惑我多日的问题。我下面简单介绍一下这个框架。

该框架用ZDE及PHP5写成,有详细文档,结构十分清晰,注释极为充分,代码非常易于读懂,说明作者写码水平非常之高。作者明确说明,这套框架参考了ASP点NET及Borland Delphi的概念。

这个框架在验证性上非常之强(并不是指里面有什么验证登录之类的模块),十分健壮,几乎不可能有什么直接的漏洞可以从外面攻入,它是引入了规范文件这个概念做限制,很有效地解决了大量验证时的效率瓶颈,这种验证方法只有一个问题就是规范文件本身的制作比较费力(当然用工具的话是另一回事了),然而一旦做好(规范文件本身有格式与规范的),验证就自然而然地由框架去做了,而无需每次人为调用。它的事件也可以定义在规范文件之内(我却认为这就没有必要了),其实它的规范文件就有点类似于DELPHI或是VB中的FORM定义文件,只不过是用XML写的纯文本,而非可视化。而对于事件驱动,框架内置了一套与点NET类似的基本事件流,你可以在不同阶段定制这些事件,其实说白了,就是重新定义这几个OnXXX函数,用给定形式的参数,你也可以自己加入自己的事件,比如你在定义自己的组件时,在规范文件中定义好该组件可能有的事件函数及参数,以后你在使用该组件时可以直接定义这些被允许的函数——不过我认为这种方式过于复杂,且要大量读入并分析XML文件,虽然十分地严谨,很安全,但有些过分了,也没有充分利用到PHP本身的灵活性,我的思路是用类似于 DELPHI的函数句柄赋值的办法或是用C的回调函数的特性,即可在写代码时在任何时间任何地点定义事件,而仍然能明确事件发出者及类型并有足够地安全性保证,且无需机械地强制各个组件只能有哪些事件,代码修改及扩展都十分方便。当然,在做大项目的时候,严格的定义是必要的,不过,即使如此,该框架处理事件的方法还是有些古板。

I think its template is a better idea. Its template is somewhat similar to the ASP file of NET before compilation (I am not familiar with ASP NET, but I understand some principles), but it works. The method is similar to DELPHI's FORM file, which is a good concept. The only disadvantage is that it is not very convenient to use a WYSIWYG general editor such as DW, because several interactive elements can be combined in one template at the same time. The components that are excluded are placed together, and which ones are decided to be displayed only during runtime.

As far as I look at the code of this framework, I still find that it has some very weak items. The most important one is the path problem. The scalability is very low. It should be more suitable for dedicated hosts. There is nothing you can do about some restricted hosts (directory restrictions or permission restrictions), and there are no corresponding reminder measures (and no related interface). It uses a cumbersome mechanism called assetService to determine the path of certain resources or files. The author himself also said that if this service is used, system consumption will increase significantly. In fact, this is borrowed from The concept of asset library in FLASH allows you to specify the path arbitrarily, but it must be re-verified every time, which is not worth the gain. My approach is to fix several main paths, and their subdirectories can be arbitrary, which comprehensively balances the contradiction between the two. Due to the lack of consideration of path issues, the framework is powerless with language settings, personalized templates, etc. If you want to translate a project, it is conceivable that the procedures are complicated, the workload is huge, and it is easy to make mistakes. This is the single most serious problem with the framework.

Generally speaking, the concept, design, and code of this framework are absolutely first-class. Of course, there are always shortcomings, but this does not prevent us from studying and learning it at all. I have not read all of its code, only a few core programs and some instructions, but I can clearly see its structure and ideas. I deeply admire the author, but I also deeply regret the shortcomings. No matter what, it is definitely a good work for studying PHP event-driven code. Therefore, it is highly recommended!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508250.htmlTechArticleThe concept of event-driven is broad. It can be on the client side or on the server side. In WEB applications, events on the client are based on JS or plug-ins or JAVAAPPLET and the like...
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

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

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

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

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor