Home

PSR12

PSR-12 is a PHP coding style guide published by the PHP Framework Interop Group (PHP-FIG) in 2019. It provides a comprehensive set of rules for writing PHP code with a consistent style across projects and is intended to be used alongside PSR-1 Basic Coding Standard and PSR-2 Coding Style Guide. PSR-12 supersedes PSR-2 and reflects modern PHP practices while remaining compatible with established PSR-1 conventions.

PSR-12 expands PSR-2 by embracing features introduced in newer PHP versions, including type declarations, namespace usage,

Key areas addressed by PSR-12 include file structure and ordering of declarations, spacing and indentation, control

Adoption and tooling: there is no runtime enforcement of PSR-12, but projects commonly use static analyzers

and
contemporary
syntax
forms.
It
aims
to
unify
coding
style
for
new
PHP
codebases
while
allowing
existing
PSR-2
code
to
gradually
adapt.
The
standard
covers
a
wide
range
of
topics
relevant
to
everyday
PHP
development,
from
file
layout
and
namespace
and
use
statement
organization
to
class
structure,
method
declarations,
and
property
typing.
structure
formatting,
visibility
and
type
declarations
for
properties
and
methods,
naming
conventions,
and
documentation
practices.
It
also
provides
guidance
related
to
autoloading
compatibility
and
code
annotations,
such
as
PHPDoc
blocks,
to
improve
readability
and
tooling
support.
and
linters,
such
as
PHP_CodeSniffer,
configured
with
a
PSR-12
ruleset
to
enforce
conformance.
The
standard
is
widely
used
by
modern
PHP
projects
and
frameworks
to
promote
consistency
across
packages,
and
it
is
maintained
by
the
PHP-FIG
with
periodic
updates
to
reflect
evolving
language
features.
See
also
PSR-1
and
PSR-2
for
related
standards.