What is PHP-FIG and what are its standards?
Jun 24, 2025 am 12:53 AMPHP-FIG matters because it created shared standards for PHP frameworks. Before PHP-FIG, frameworks used different methods for tasks like autoloading and HTTP handling, making code reuse difficult. The group introduced PSRs like 1. PSR-1 (coding style basics), 2. PSR-4 (autoloading standard for namespaces), and 3. PSR-7 (HTTP message interfaces), enabling cross-framework compatibility. Other key standards include PSR-12 (extended style), PSR-3 (logging), and PSR-11 (container interface). Developers can adopt these standards using Composer for autoloading, tools like PHP_CodeSniffer for code style enforcement, and by building reusable packages with PSR-7 or PSR-11 support. Following major PSRs improves interoperability and reduces development complexity.
PHP-FIG stands for the PHP Framework Interop Group, and it's basically a group of PHP framework representatives who got together to talk about common standards. The goal was simple: make it easier for different PHP frameworks and libraries to work together.
Why PHP-FIG Matters
Before PHP-FIG, each PHP framework had its own way of doing things — from autoloading classes to handling HTTP requests. This made it hard for developers to switch between frameworks or reuse code across projects. PHP-FIG aimed to fix that by creating shared standards.
The cool part? These aren't official PHP rules — they're just recommendations. But over time, most major PHP projects and frameworks (like Laravel, Symfony, and Composer) adopted them. That makes life a lot easier if you're building with PHP today.
The Big Standards You Should Know
Here are some of the main standards (called PSRs — PHP Standard Recommendations) that came out of PHP-FIG:
PSR-1: Basic Coding Standard
This is like the ground floor of good PHP style. It covers basic stuff like:
- Class names should be in
StudlyCaps
- Method and variable names can be in
camelCase
- PHP files should only contain PHP code (no HTML or other stuff at the start or end)
It’s not super detailed, but it sets a baseline so everyone’s on the same page when reading code.
PSR-4: Autoloading Standard
This one’s huge. Before PSR-4, every framework had its own way of auto-loading classes. Now, most use PSR-4.
What does it do?
It says how class files should be named and where they should live based on their namespace. So if you have a class called App\Utils\Logger
, PSR-4 tells you to look for it in a file like src/Utils/Logger.php
under the App
directory.
Composer uses this by default, which makes including third-party packages much smoother.
PSR-7: HTTP Message Interfaces
This standard defines interfaces for HTTP messages — things like requests and responses. It means libraries can work with any framework that supports PSR-7, instead of being locked into one.
So if you build a middleware that works with PSR-7, it can plug into Slim, Lumen, or any other compatible framework.
Other important ones include:
- PSR-12 – Extended coding style (builds on PSR-1)
- PSR-3 – Logging interface
- PSR-11 – Container interface
They’re not all required, but the more your project follows them, the easier it’ll play with others.
How to Use These Standards in Real Life
If you're using a modern PHP framework, chances are you're already following most of these without thinking about it. Here’s how to take advantage more intentionally:
-
Use Composer – It supports PSR-4 autoloading out of the box. Just define your namespaces and directories in
composer.json
. - Check your code style – Tools like PHP_CodeSniffer or PHP-CS-Fixer can help enforce PSR-1 or PSR-12.
- Build reusable packages – If you want your library to work across frameworks, implement PSR-7 or PSR-11 where applicable.
You don’t have to follow every PSR, but sticking to the big ones will save headaches down the line.
That’s the gist of PHP-FIG and its standards — basically a set of agreements that make PHP projects more compatible and easier to work with. Not magic, just practical collaboration.
The above is the detailed content of What is PHP-FIG and what are its standards?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Common problems and solutions for PHP variable scope include: 1. The global variable cannot be accessed within the function, and it needs to be passed in using the global keyword or parameter; 2. The static variable is declared with static, and it is only initialized once and the value is maintained between multiple calls; 3. Hyperglobal variables such as $_GET and $_POST can be used directly in any scope, but you need to pay attention to safe filtering; 4. Anonymous functions need to introduce parent scope variables through the use keyword, and when modifying external variables, you need to pass a reference. Mastering these rules can help avoid errors and improve code stability.

To safely handle PHP file uploads, you need to verify the source and type, control the file name and path, set server restrictions, and process media files twice. 1. Verify the upload source to prevent CSRF through token and detect the real MIME type through finfo_file using whitelist control; 2. Rename the file to a random string and determine the extension to store it in a non-Web directory according to the detection type; 3. PHP configuration limits the upload size and temporary directory Nginx/Apache prohibits access to the upload directory; 4. The GD library resaves the pictures to clear potential malicious data.

There are three common methods for PHP comment code: 1. Use // or # to block one line of code, and it is recommended to use //; 2. Use /.../ to wrap code blocks with multiple lines, which cannot be nested but can be crossed; 3. Combination skills comments such as using /if(){}/ to control logic blocks, or to improve efficiency with editor shortcut keys, you should pay attention to closing symbols and avoid nesting when using them.

AgeneratorinPHPisamemory-efficientwaytoiterateoverlargedatasetsbyyieldingvaluesoneatatimeinsteadofreturningthemallatonce.1.Generatorsusetheyieldkeywordtoproducevaluesondemand,reducingmemoryusage.2.Theyareusefulforhandlingbigloops,readinglargefiles,or

The key to writing PHP comments is to clarify the purpose and specifications. Comments should explain "why" rather than "what was done", avoiding redundancy or too simplicity. 1. Use a unified format, such as docblock (/*/) for class and method descriptions to improve readability and tool compatibility; 2. Emphasize the reasons behind the logic, such as why JS jumps need to be output manually; 3. Add an overview description before complex code, describe the process in steps, and help understand the overall idea; 4. Use TODO and FIXME rationally to mark to-do items and problems to facilitate subsequent tracking and collaboration. Good annotations can reduce communication costs and improve code maintenance efficiency.

TolearnPHPeffectively,startbysettingupalocalserverenvironmentusingtoolslikeXAMPPandacodeeditorlikeVSCode.1)InstallXAMPPforApache,MySQL,andPHP.2)Useacodeeditorforsyntaxsupport.3)TestyoursetupwithasimplePHPfile.Next,learnPHPbasicsincludingvariables,ech

In PHP, you can use square brackets or curly braces to obtain string specific index characters, but square brackets are recommended; the index starts from 0, and the access outside the range returns a null value and cannot be assigned a value; mb_substr is required to handle multi-byte characters. For example: $str="hello";echo$str[0]; output h; and Chinese characters such as mb_substr($str,1,1) need to obtain the correct result; in actual applications, the length of the string should be checked before looping, dynamic strings need to be verified for validity, and multilingual projects recommend using multi-byte security functions uniformly.

ToinstallPHPquickly,useXAMPPonWindowsorHomebrewonmacOS.1.OnWindows,downloadandinstallXAMPP,selectcomponents,startApache,andplacefilesinhtdocs.2.Alternatively,manuallyinstallPHPfromphp.netandsetupaserverlikeApache.3.OnmacOS,installHomebrew,thenrun'bre
