LLMpediaThe first transparent, open encyclopedia generated by LLMs

PSR-12

Generated by GPT-5-mini
Note: This article was automatically generated by a large language model (LLM) from purely parametric knowledge (no retrieval). It may contain inaccuracies or hallucinations. This encyclopedia is part of a research project currently under review.
Article Genealogy
Parent: symfony Hop 4
Expansion Funnel Raw 61 → Dedup 0 → NER 0 → Enqueued 0
1. Extracted61
2. After dedup0 (None)
3. After NER0 ()
4. Enqueued0 ()
PSR-12
NamePSR-12
ClassificationCoding style guide
StatusFinal
Year2019
AuthorsPHP Framework Interop Group
RelatedPSR-1, PHP-FIG

PSR-12 PSR-12 is a coding style guide that extends PSR-1 and supersedes informal conventions to define a standardized format for PHP source code. It provides explicit rules for formatting, indentation, and structure intended to improve interoperability between projects, libraries, frameworks, and tooling across the PHP ecosystem. The specification was produced by the PHP-FIG and has influenced style enforcement in major projects and vendor ecosystems.

Overview

PSR-12 formalizes conventions for file structure, line length, indentation, and control structure formatting to ensure consistent presentation across projects such as Symfony (software), Laravel (web framework), Zend Framework, WordPress, and Drupal. It builds on PSR-1's basic coding standards and complements recommendations from linters and formatters used by organizations like Facebook, Google, Microsoft, Amazon (company), and JetBrains. The guide defines constraints for namespace declarations, use statements, class declarations found in repositories like GitHub, GitLab, and Bitbucket, and influences continuous integration pipelines used by Travis CI, CircleCI, and GitHub Actions.

History and development

PSR-12 originated within the PHP-FIG as a response to diverse conventions in projects such as CakePHP, CodeIgniter, Phalcon (software), Slim (framework), and FuelPHP. Early drafts were debated by contributors from organizations including Zend Technologies, Fabien Potencier, representatives of Symfony (software), and maintainers from Composer (software)-using ecosystems. The development process involved discussions on mailing lists, pull requests, and formal votes reminiscent of standards processes used by W3C, IETF, ECMA International, and ISO. Influential community figures and companies such as Rasmus Lerdorf, Nikita Popov, Facebook, Google, and JetBrains provided feedback that shaped final decisions on issues like trailing commas, nullable types, and multiline argument lists.

Coding style rules

PSR-12 prescribes rules for elements including opening PHP tags, file encoding, and declaring strict types, mirroring decisions in projects like Symfony (software), Laravel (web framework), and Drupal. It mandates 4-space indentation common to codebases maintained by Google, Microsoft, Apple Inc., and Oracle Corporation, sets a soft line length recommendation analogous to guidance from PEP 8 authors at Python Software Foundation and style committees at Mozilla Foundation, and defines spacing around operators used in libraries by Swift (programming language) teams at Apple Inc.. The specification addresses class member visibility ordering seen in code from Facebook, Twitter, Inc., LinkedIn, and Stripe, Inc., and provides conventions for control structures and anonymous functions used in frameworks like Zend Framework, Symfony (software), and Laravel (web framework). It also covers return type declarations and nullable types as introduced by contributors such as Nikita Popov and adopted in platforms like Drupal and WordPress.

Tooling and automation

Tooling ecosystems adapted PSR-12 rapidly: formatters like PHP-CS-Fixer, linters such as PHPCS, and IDE integrations from JetBrains's PhpStorm and editors like Visual Studio Code incorporated rulesets to automate compliance. Continuous integration providers including Jenkins, Travis CI, CircleCI, and GitHub Actions often include PSR-12 checks alongside test suites managed by PHPUnit and dependency management via Composer (software). Static analysis tools like Psalm (software), PHPStan, and plugins for SonarQube enforce style and type-safety in enterprise environments operated by companies such as Amazon (company), Microsoft, Google, and Facebook.

Adoption and impact

PSR-12's adoption is visible in major open-source projects and enterprise codebases maintained by organizations like Automattic, Acquia, Shopify, Hyatt, and consultancy firms integrating PHP into stacks alongside Docker, Kubernetes, AWS, and Azure. Popular frameworks including Symfony (software), Laravel (web framework), Zend Framework, and Drupal reference PSR-12 in contribution guides, influencing coding practices in developer communities coordinated through platforms like GitHub and GitLab. Style standardization has facilitated cross-team collaboration, code reviews, and automated refactoring in toolchains used by corporations such as Google, Facebook, Microsoft, and Amazon (company), and has been cited in developer handbooks associated with universities like MIT and Stanford University when teaching modern web development workflows.

Category:PHP