search
HomeBackend DevelopmentPHP TutorialPHP比你想象的好得多_php基础

有很多对于PHP的抱怨,甚至这些抱怨也出自很多聪明的人。当Jeff Atwood写下对于PHP的另一篇抱怨文章之后,我思考了下PHP的好的方面。

  这些抱怨最大的问题是他们出自很多仍在使用旧版本PHP的人。他们或许是不愿意关心或许是不愿意承认PHP不管在语言层面还是在社区层面都在以很快的速度演变。实际上它比任何其他语言或者web平台都演变的快。尽管并不总是如此,但是过去的五年PHP经历了一个惊人的历程。

  在说最近PHP社区取得的惊人成就之前,我们先来看看一些有趣的数字:PHP被77.9%的服务端编程语言已知的网站使用。Wordpress被全世界16.6%的网站使用。使用率最高的三个CMS建站系统是:第一的Wordpress份额为54.3%,第二的Joomla份额为9.2%,第三的Drupal份额为6.8%。这三个产品都是用PHP写的。

  PHP一定做了一些正确的事,不是吗?

  现在,我来告诉你吧,PHP的绝技在于:尽管经过了这么多年的变化,PHP对于非技术人员依然是最容易学习的语言,它让人可以比其他技术更快地建立动态网站,也让人没有麻烦地托管网站。PHP可能不是这个世界上设计最好的语言,但是它能让你完成事情(get things done),这一点是毋庸置疑的。

 

  PHP语言

  PHP5.0(2004年发布)带来了很实用的对象模型…等等,我在说8年前发布的东西。快进到现在的PHP5.4,即PHP最近的版本,带来了对于现代web语言你梦寐以求的东西:是的,PHP支持了命名空间(namespaces);是的,PHP支持闭包(closure);是的,PHP支持traits。

  尽管需要花费一些时间,但是PHP5.4带来了一些语法糖使得整体体验比以往更好:是的,PHP支持用[ ]定义数组;是的,PHP支持新创建的对象这样调用函数:(new Foo())->bar();是的,PHP支持数组这样获取元素:$foo->bar()[1]。

  PHP甚至向它自己曾犯过的错误学习:register_globals 和 magic_quotes被彻底删除了。

  PHP有了内置web服务器以方便本地测试,它能以微秒级的速度启动。

  接下来的挑战:我们怎样更新在网络上的讲解PHP的教程?在PHP程序中最好的支持WebSocket的技术是什么?

  PHP生态系统

  拥有一个好的语言是很好的,但是拥有一个好的生态系统更棒。在过去的几年PHP生态系统演变了很多。

  Git

  对于Git我不想讨论太多,Git被到处使用,PHP很快拥抱了Git。几乎所有PHP类库、框架和产品都在使用Git,包括PHP本身。

  Composer

  两年前,我想去掉我在symfony 1中hack的丑陋PEAR代码以支持插件。我想替换成能管理项目依赖的东西,而不是一个像PEAR一样的整体的安装,所以我试着寻找能管理软件依赖的最佳的算法。我几乎尝试了所有可能:从Perl到Ruby,从Debian到Redhat。结果没有让我满意的,只有我自己的解决方案恰巧能工作…当然这只是我的经验只谈。之后我偶然发现了ZYpp,就是它了。ZYpp使用布尔可满足性问题解来管理依赖。多亏了Nils AdermannJordi Boggiano的辛苦工作,PHP现在有了做好的管理依赖的工具–Composer

  是的,PHP比其他语言有了更好的依赖管理工具。

  由于有了Git,Composer,和PHP内置web服务器,我们更容易下载/测试/安装一个PHP项目。

  想测试Symfony(使用PHP5.4)?

复制代码 代码如下:

$ composer.phar create-project symfony/framework-standard-edition
$ cd framework-standard-edition
$ ./app/console server:run

想测试Silex?

复制代码 代码如下:

$ composer.phar create-project fabpot/silex-skeleton
$ cd silex-skeleton
$ php -S localhost:8888 -t web/

还不知道Composer?你应该了解下它了。

  浏览下主要的Composer仓库Packagist,它已经拥有1900多个包,且它们在不到三个月的时间里被安装了上百万次。

  接下来的挑战:在下一个PHP版本里内置Composer?

  合作

  社区合作是本文说的重点,也是我最引以为豪的地方。我们开始看到PHP项目中更好的合作,甚至大项目也是如此,大到你可以忽略其他项目了。

  phpBB,Drupal,ez Publish,Symfony,和很多其他项目(比如phpDocumentor, PHPUnit, Behat, Zikula, Propel, Doctrine, Midgard等等)都在共享代码。是的,他们彼此是竞争者,但是他们都理解彼此合作是很重要的。Composer能很好地促进这种合作。

  接下来的挑战:说服更多的项目加入这个趋势中来。

  结论

  让我再重申一次,PHP可能不是最好的编程语言,我也是第一个说出它的怪处的,但是PHP是迄今为止最好的web平台。

译自:PHP is much better than you think

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
Beyond the Hype: Assessing PHP's Role TodayBeyond the Hype: Assessing PHP's Role TodayApr 12, 2025 am 12:17 AM

PHP remains a powerful and widely used tool in modern programming, especially in the field of web development. 1) PHP is easy to use and seamlessly integrated with databases, and is the first choice for many developers. 2) It supports dynamic content generation and object-oriented programming, suitable for quickly creating and maintaining websites. 3) PHP's performance can be improved by caching and optimizing database queries, and its extensive community and rich ecosystem make it still important in today's technology stack.

What are Weak References in PHP and when are they useful?What are Weak References in PHP and when are they useful?Apr 12, 2025 am 12:13 AM

In PHP, weak references are implemented through the WeakReference class and will not prevent the garbage collector from reclaiming objects. Weak references are suitable for scenarios such as caching systems and event listeners. It should be noted that it cannot guarantee the survival of objects and that garbage collection may be delayed.

Explain the __invoke magic method in PHP.Explain the __invoke magic method in PHP.Apr 12, 2025 am 12:07 AM

The \_\_invoke method allows objects to be called like functions. 1. Define the \_\_invoke method so that the object can be called. 2. When using the $obj(...) syntax, PHP will execute the \_\_invoke method. 3. Suitable for scenarios such as logging and calculator, improving code flexibility and readability.

Explain Fibers in PHP 8.1 for concurrency.Explain Fibers in PHP 8.1 for concurrency.Apr 12, 2025 am 12:05 AM

Fibers was introduced in PHP8.1, improving concurrent processing capabilities. 1) Fibers is a lightweight concurrency model similar to coroutines. 2) They allow developers to manually control the execution flow of tasks and are suitable for handling I/O-intensive tasks. 3) Using Fibers can write more efficient and responsive code.

The PHP Community: Resources, Support, and DevelopmentThe PHP Community: Resources, Support, and DevelopmentApr 12, 2025 am 12:04 AM

The PHP community provides rich resources and support to help developers grow. 1) Resources include official documentation, tutorials, blogs and open source projects such as Laravel and Symfony. 2) Support can be obtained through StackOverflow, Reddit and Slack channels. 3) Development trends can be learned by following RFC. 4) Integration into the community can be achieved through active participation, contribution to code and learning sharing.

PHP vs. Python: Understanding the DifferencesPHP vs. Python: Understanding the DifferencesApr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP: Is It Dying or Simply Adapting?PHP: Is It Dying or Simply Adapting?Apr 11, 2025 am 12:13 AM

PHP is not dying, but constantly adapting and evolving. 1) PHP has undergone multiple version iterations since 1994 to adapt to new technology trends. 2) It is currently widely used in e-commerce, content management systems and other fields. 3) PHP8 introduces JIT compiler and other functions to improve performance and modernization. 4) Use OPcache and follow PSR-12 standards to optimize performance and code quality.

The Future of PHP: Adaptations and InnovationsThe Future of PHP: Adaptations and InnovationsApr 11, 2025 am 12:01 AM

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),