Home Backend Development PHP Tutorial 为什么我要使用自己编写的框架(而且你也应该)

为什么我要使用自己编写的框架(而且你也应该)

Jun 20, 2016 pm 12:26 PM

Photo by Anton Repponen​

注:本篇文章主要是针对有经验的开发者,尽管本文内容适用性很广,但我并不建议所有人都去创建并维护自己的框架,除非你很清楚自己在干什么。

在我们 PHP 社区,开发者的身份通常与这门语言和所采用的框架紧密地绑定在一起。说不清是好还是坏,我们的职业生涯也与某一技术平台紧密相连,同时还投入了大量的精力在这个平台及其文化和支持工具上。

然而,相比编程语言本身,工具的生命周期要短的多。在 PHP 社区中,有无数的框架涌现然后消逝,将来还会有更多的框架出现、流行,最后淡出视野。这是事物的自然规律。

这其实没什么大不了,因为框架本身并不重要,重要的是蕴含在框架之内,在开发实践中我们所信奉的一系列原则。

框架代表了一种固执己见的软件开发方法,框架维护者通过框架给出了软件应该是什么样子的一个范例。而使用者,无论是出于义务还是认同,他们信奉并采用了框架维护者的这种开发哲学。

但我们今天接受的范例可能在未来被新的所取代,所以框架总是不断更替。

在多年尝试寻找最好的框架未果后,我认识到对我来说真正重要的不是正确的范例,而是正确的实践。正因为如此,我意识到我需要开发、维护和使用我自己的框架,一个能代表我所信奉的一系列原则而不是某一特定时刻非常有用的各类范例的框架。

老实说,将我自己使用的骨架代码称之为框架多少有点难为情,因为大部分的核心功能都不是我自己实现的。事实上,我采用了许多其他的包,这些包所代表的最佳实践非常有用。我自己的框架扮演了“胶水”代码的角色,将这些包有机地组织在了一起。

这是我们这个时代的编程之美——轻松地整合各类不相干的包并创建出新的东西。对于任何一个框架或库,你都不用全盘接受,你可以从这取一点,从那拿一些,只采用你认为有用的部分。当我刚开始接触 PHP 时这一切都很难想象,直到有了Composer.

我把注意力集中在拥抱那些对我很重要的原则和实践上,而不是某一特定框架的主张和范例。这招儿对我很管用。

当忙碌的一天结束时,最为重要的是代码的可读性、可维护性和正确性。当前流行的范例终有一天会被取代,但衡量代码品质的标准却会长存。

所以,是时候停止寻找所谓的完美框架了,把精力集中在最佳实践和如何将其纳为己用上吧。

我为创建、维护和使用自己的框架而自豪!

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 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)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

See all articles