Home Backend Development PHP Tutorial PHP框架,伤不讫啊伤不起

PHP框架,伤不讫啊伤不起

Jun 13, 2016 pm 01:07 PM
codeigniter php rails request ruby

PHP框架,伤不起啊,伤不起

自从Rails刮起了一阵框架风,其它语言群起响应,Java,Python,Scala,PHP,无论静态动态语言都出现了模仿Rails模式的框架出现,其中,PHP语言的框架生产力更是一流,主流的PHP框架就有超过5种,加上不出名的框架的话,我估计起码有20多种框架,可怕的数量!!

PHP框架之路一直充满着争议,从PHP要不要用框架,到应不应该模仿Rails,却抵不上PHP框架的井喷式的增长,各类框架你方唱罢我登场,网上仅仅是罗列部分框架和简介就能成为一片文章,名为《国外十大最流行PHP框架排名》。PHP框架中比较知名的有:CodeIgniter、CakePHP等中小型框架和Zend、Symfony等大型框架。我一直在想为什么PHP的框架数量如此之多呢?
1. PHP开发框架太‘容易’了
不要骂我,说实话,PHP开发Web框架的门槛比起其他的语言,真的要低太多了,PHP本身已经有了对Web的支持,要做一个框架,只要先写一个单入口index.php,然后通过module和action参数执行对应的Controller类,和View代码,一个非常简单的框架就好了,熟练的程序员一两天就完成了。如果觉得太简单,再稍微封装一下,把$_REQUEST,$_SESSION封装一下,封装一下数据库操作等等。到这里一个有模有样的PHP‘MVC框架’就基本出炉了。熟练一点程序员一周时间搞定了。
相反其他语言,以ruby为例,光是对REQUEST的处理,参数解析等基础功能实现,就远远不止一周的工作量,在加上ruby语言的高灵活性和复杂的语法,使他开发一款拿的出手的框架所需要的精力是大大的超越一般,开发框架的门槛低是PHP框架泛滥的因素之一。

?

2. PHP的封装能力弱,致使框架的灵活度不够
这也是事实,PHP的框架很多,但是一般要评估项目,来选择适当的框架,如果是一个简单的web项目,一般选择CodeIgniter、CakePHP这类框架,如果是大型的应用,也会选择Zend、Symfony等大型框架,因为你会发现使用Zend和CodeIgniter完全是两回事。
也许我说的抽象了,那我举个例子:在默认的PHP环境中,是没有AOP功能的,不能对类的已有方法进行功能性增强,在需要实现类似功能的情况下,你就需要显示的修改外面的代码,非常流行的做法是利用PHP的魔法函数,但是依然需要修改对象的创建方法。
依然对比Ruby,它几乎是内置了AOP支持,可以在完全外部调用完全不变的情况下完成功能的增强。
在框架的封装中这种能力的差异就更加的显著,在PHP中框架复杂度高也提高了使用者的难度,而不能像Ruby等完全将复杂性隐藏在框架的内部。(说句题外话:javascript也是如此,jquery便是佐证)。

?

3. PHP的实现机制,使得框架的性能成为诟病
PHP的运行模式,每次request结束都会完全释放所有资源,导致框架的加载成为了一个不可忽视的性能累赘,即使你不介意上面提到大型框架的使用复杂度高,这个原因也让你不会在中小型项目中轻易使用Zend等大型框架。同时也限制了框架的能力。

据我分析,正是这三个原因,使得PHP的框架如此之多,但是没有一个成为真正的主流。这种情况未必是好事,在Ruby中,Rails一统,使得Rails社区空前繁荣,很多Ruby高手开发各种插件增强的它的功能。使得它有着十分良性的发展。在js框架中jquery也有着相同的经历。
在PHP中,高手则是不停的贡献它们的新框架,老实说我个人觉得帮助很有限,更是搅浑了这一缸水,其实很多框架完全可以合并为一个发展,与其出现100个60分的框架,不如出现一个100分的好框架。PHP框架,多的让我伤不起啊伤不起。?

Statement of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

See all articles