首頁 >php教程 >php手册 >霍然回首 ,PHP 竟然就是一个框架

霍然回首 ,PHP 竟然就是一个框架

WBOY
WBOY原創
2016-06-06 19:55:031411瀏覽

(原题目:Last we checked, PHP is a framework. By Akash Mehta. June 8th, 2008 ) When it comes to web programming languages, PHP probably holds the record for copping criticism from the community at large. Comparisons with alternatives such a

(原题目:"Last we checked, PHP is a framework".  By Akash Mehta. June 8th, 2008 )



When it comes to web programming languages, PHP probably holds the record for copping criticism from the community at large. Comparisons with alternatives such as Ruby on Rails and Python/Django are common; defenders of PHP are quick to criticise the comparison of a language and a framework. But at the end of the day, developers work with Ruby on Rails, and with Python/Django, and with PHP. Just PHP. For most of the PHP applications out there, the language is just perfect, because PHP, to an extent, is the framework.


在谈到web编程语言时,PHP可能是受到社区最多批评的语言了。与其它同类语言如Ruby on Rails 和 Python/Django 作比较是经常的事了;PHP的护卫者们常常批评这些对语言和框架所进行的比较。但到了最后,使用Ruby on Rails的,和使用Python/Django的, 和使用PHP的开发者,都会使用PHP。对大多数现存的PHP应用,语言真是太好了,因为PHP,在一定程度上,就是一种框架。

PHP is designed for the web. You could plug vanilla Ruby or Python into a web server and get up and running pretty quickly. But, at least at a basic level, you’d want a framework to deal with common issues of web development. In PHP, you just get started. PHP and Apache work out request data, output handling and more, right out of the box. (PHP also masters deployment.) David Heinemeier Hanson, the creator of the Ruby on Rails framework, calls this the immediacy of PHP.


PHP就是为web而设计的。用户也可以把纯粹的Ruby和Python应用放在web服务器里并可以运行得很好。但是,至少在基础水平 上,用户还是希望使用框架来处理那些通常web开发会遇到的问题。使用PHP时,只要你动手就行了。PHP和Apache会在内部来处理需要的数据,输出 处理等问题。Ruby on Rails 框架的创造人David Heinemeier Hanson形容其为PHP的直接性。


Now, consider the “average” PHP frameworks. They help you handle request data, manage your output, control app flow - essentially, extending PHP’s inbuilt functionality. They are, therefore, PHP frameworks on the PHP framework. PHP provides a vast array (pardon the pun) of functionality out of the box. But when you want to do things your way, it gets out of the way, and this is really important when building anything beyond a simple database frontend.


现在,分析一下"普通的"PHP框架。框架可用于处理需要的数据,管理输出,控制应用流程 -- 基本上,就是扩展了PHP内建的函数功能。因此,也可以说,它们只是基于PHP框架上的PHP框架。PHP是提供了一大把可用函数,但如果你想按自己的方 式来行事,那还是不够的,但有时候,后者在你想做一些诸如比简单的提取数据放在网页上更复杂的事情时,还是挺重要的。

How many PHP applications in wide distribution are built on a third-party framework? MediaWiki? No framework here. Wordpress? Not here either. Drupal? You get the idea. Each of these applications have their own framework, inasfar that the developers built a structure for their code that suited what they were trying to create. These three, and the countless others, clearly did something right - MediaWiki even powers one of the world’s top 10 websites. And when building these “frameworks”, PHP helped them along the way.


有多少广泛分布的PHP应用是建立在第三方的公用框架上的呢?MediaWiki? 没用这些框架。Wordpress? 也没用这些框架。Drupal又如何? 看到这里,你应该明白了。这里的每个应用都有它们自己的框架,在这里开发者为他们的应用量身订造出合适的结构。这三个应用,联同其它无数的应用一样,做得 正确无误 -- MediaWiki网甚至成为了世界10个顶级网站之一。在建造这些"框架"时,PHP顺其自然地做了自己的事情。


Sure, Cake, Symfony, CI - they all help you build PHP applications. But unlike a Ruby framework or a Python framework, coding is perfectly tolerable without them. Of course, most developers tend to create their own framework as they go along - I call this PHP’s DIY framework mentality, where you build the last level in your stack, and by extension you know exactly what’s going on under the hood.


没错,Cake, Symfony, CI(Codelgniter) -- 都可以帮你开发PHP应用。但和使用Ruby框架或Python框架不一样的是,即使不用这些PHP框架,程序一样地好写。当然了,很多开发者都倾向于创 造自己的框架 -- 精神上我称之为PHP的自做框架,在那可以根据自己的需要来开发,并扩展自己最清楚的内部系统功能。


This comes back to the oft-cited “best tool for the job” argument - but by being a “half framework” of sorts, PHP simply helps you within a web context. I’m sure Rails is great for countless applications; Ruby syntax helps a little too. But beyond the basics, the language becomes increasingly irrelevant, and a framework will force you to build your app according to design decisions made by the original developers. On the other hand, PHP allows you to quickly put together your application the way you want, helping you with the web-based aspect, and without having to break the language/framework to achieve your goals. Essentially, PHP is the web layer without the framework baggage.


Twitter recently had some downtime that could be attributed to its use of Ruby on Rails. Now, there’s nothing wrong with Ruby, or Rails. But Twitter is a messaging system, RoR is an application framework. Could Rails be worked around to suit Twitter? Maybe. Could Twitter have avoided these problems if they’d used PHP? Probably. Twitter’s developers have noted they weren’t quite expecting the site to be so succesful. If they had built it in PHP, they would probably have encountered other (similar) problems earlier on, rewritten the entire app while it was still feasible, and built a powerful system that could scale just fine (likely with the messaging platform in C). Using PHP could have helped, not as a language with syntax and libraries as such, but as a web development platform that gives developers the freedom to architect their systems as they want. (They could also have tried Erlang.)


So the next time you’re on the lookout for a PHP framework to build your killer app on, consider using the best framework of them all: PHP. It will give you the freedom to achieve what you want, how you want, with results. A quick hack? Check the manual, it could be a one-liner. A massive distributed messaging platform? Full steam ahead, build it your way. For everything in between, there’s a multitude of options, but if you have the time, PHP is all the framework you need.

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn