事件驱动这个概念是广义的。可以在客户端,也可以在服务器端。
在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的回调函数的特性,即可在写代码时在任何时间任何地点定义事件,而仍然能明确事件发出者及类型并有足够地安全性保证,且无需机械地强制各个组件只能有哪些事件,代码修改及扩展都十分方便。当然,在做大项目的时候,严格的定义是必要的,不过,即使如此,该框架处理事件的方法还是有些古板。
它的模板我认为是一个比较好的想法,它的模板有些类似于点NET的ASP文件在编译前的文件(我对ASP点NET并不熟,但明白一些原理),但起作用的方式则类似于DELPHI的FORM文件,是一个很好的概念,唯的一缺点是用DW之类所见即所得的通用编辑器则感觉不是很顺手,因为一个模板中可以同时把几个互斥的组件放在一起,而只在运行过程中决定显示哪些。
就我本人看该框架的代码,还是发现它有一些非常弱的项。其中最主要的一个就是路径的问题,可扩展性很低,应该比较适用于专用主机,对一些受限主机(目录限制或是权限限制)就无能为力了,也无相应的提醒措施(也无相关接口)。它对某些资源或文件的路径,用了一种繁琐的叫assetService的机制,目的就是确定文件的路径,作者自己也说,如果用了这个服务,系统消耗会明显增加,其实这个是借鉴了FLASH中asset library的概念,它这样虽然可以任意指定路径,但每次都必须重新校验,有些得不偿失。我的作法则是固定好几个主要路径,而其的子目录都可随意,就综合平衡了两者的矛盾。由于对路径问题缺乏考虑,导致该框架对语言设置、个性化模板等无能为力,如要翻译一个项目,手续之繁,工作量之大是可想而知的,而且极易出错。这是该框架中最严重的一个问题。
从总体上来说,该框架的理念上,设计上,代码上绝对都属一流。当然不足总是有的,不过完全不妨碍我们研究及学习它。它的代码我并未全看,只主要看了几个核心程序及一些说明,但已能足够看清楚其结构与思想,对作者深表佩服,但对其中的不足也深表遗憾。不管怎么样,它都绝对是研究PHP事件驱动代码的好作品。因此强烈推荐!

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.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

Key players in HTTP cache headers include Cache-Control, ETag, and Last-Modified. 1.Cache-Control is used to control caching policies. Example: Cache-Control:max-age=3600,public. 2. ETag verifies resource changes through unique identifiers, example: ETag: "686897696a7c876b7e". 3.Last-Modified indicates the resource's last modification time, example: Last-Modified:Wed,21Oct201507:28:00GMT.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Linux new version
SublimeText3 Linux latest version

Zend Studio 13.0.1
Powerful PHP integrated development environment