search
HomeBackend DevelopmentPHP Tutorial通过四种方式让PHP编码变得更轻松_PHP

 

尽管已经目前PHP语言已经建立起属于自己的软件文化,但要找到它令人抓狂的弊端也绝对不是难事。我们曾经在之前的文章中列出过该语言最让开发人员难以接受的十二大糟糕特性。

不过在过去几年当中,PHP已经发生了一系列变动——从语言本身到相关生态系统再到对开发者社区的支持——这些确实值得我们加以关注。尽管已经抛弃了PHP并投身于Python或者Ruby的用户们不太可能在短时间内被吸引回来,但已经有迹象表明确实有人在不遗余力地对PHP加以完善。下面我们就一同来了解PHP语言迎来的四大显著改进。

1. 软件包与依赖性管理

直到不久之前,对PHP软件包进行管理的惟一方式还只能是使用PEAR(即PHP扩展与应用程序库)。不过PEAR在使用难度上长期受到开发人员们的抨击,其中充斥着大量已经过时以及未受维护的软件组件。大多数更为流行的PHP框架都拥有自己的独特软件包管理系统——例如CakePHP的Bakery、CodeIgniter的Sparks等——不过它们很少或者几乎无法将PHP作为整体加以打理。

这方面最大的变化源自Composer,它吸取到了Node.js的NPM系统与Ruby的Bundler当中的优秀要素。它会以项目作为基础对软件包进行追踪,这样一来开发人员就能更轻松地弄清楚特定项目需要使用哪些软件包并以自动化方式对其加以安装。它与名为Packagist的库协同运作,该库中已经包含大量常用PHP应用、框架以及组件。

2. Hack/HHVM

PHP获得的另外两大最为显著的变化源自PHP自身体系之外——更准确地说,来自Facebook:Hack语言与HHVM(即HipHop虚拟机)。前者在继承了PHP衣钵的同时添加了一系列PHP默认状态下无法实现的功能,例如静态对象类型。后者则能够将PHP代码编译为C++代码从而加快其执行速度,最终带来将近十倍于原本的性能水平。二者都属于推出时间相对较短的创新成果,因此它们对于PHP在长远角度的影响仍然有待观察。不过它们至少显示出主流Web服务巨头确实对PHP显示出浓厚的兴趣与认真的对待态度,并因此将其作为自身选定的平台方案。

3. PHP-FIG

虽然听起来像是种解闷的小零食(Fig意为无花果),但这实际上是一个PHP框架程序组,其中汇总了PHP开发者们所打造的用于构建开发标准(包括如何以一致性方式开发自己的项目)的技术成果。来自CakePHP、Drupal、Joomla以及SugarCRM等项目的技术人员们已经正式加入该团体,并为多项日常工作提供了标准化机制——其中包括编码风格指南、库登录接口以及如何处理类的自动载入等等。

这个小组可以说是完全自愿加入而且并非正式机构,不过他们希望“随着时间的推移,其涵盖范围能够扩展到更为广泛的项目区划当中。”

4. Phpng项目

为PHP语言本体开发换代版本则是另一个为该语言带来全面提升的优秀思路。这个被称为Phpng的PHP开发分支当中包含诸多改进,旨在明确特定操作需要使用多少内存容量以及完成特定运行效果需要使用多少条机器指令。其中大部分工作都受到PHP供应商Zend技术公司的赞助,后者的PHP引擎被广泛用于该语言的商用安装方案当中。

当然,其中大部分改进仅仅是为了提升其性能表现而并非改变PHP语言那备受讥讽的语法特性——遗憾的是,这些问题目前仍没有得到解决的迹象。也许PHP的下一次重大革新不会像Hack那样具备颠覆性效果,而更像是JavaScript扩展方案那种能够实现原生编译效果的转译语言。

英文:http://www.infoworld.com/t/php-web/4-ways-php-coding-getting-less-painful-245435

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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools