pretty-php is an opinionated code formatter for PHP. It is designed to make PHP source code consistent without requiring developers to spend time choosing or maintaining an extensive collection of style rules.
The formatter takes a deterministic approach: the same input and settings produce the same formatting, helping projects avoid stylistic differences between contributors and making code review easier to follow. Its philosophy is influenced by Black, the Python formatter, with an emphasis on sensible defaults, predictable output, and producing small, readable diffs. It can be used as a standalone command-line tool or incorporated into a broader development workflow alongside linters and other quality checks.
This is free and open source software.
Key Features
- Formats complete PHP files in place.
- Offers a diff mode for reviewing proposed formatting changes without replacing files.
- Checks formatted output against the original code for equivalence.
- Supports PSR-12 and the PHP Extended Coding Style specification.
- Includes presets for Symfony, Drupal, Laravel and WordPress coding styles.
- Can group and sort import statements.
- Provides controls for operator placement and treatment of existing newlines.
- Can normalize strings and numeric literals.
- Trims and aligns comments and removes empty DocBlocks.
- Supports optional configuration through a JSON file while remaining usable without configuration.
- Can be integrated with editors and continuous integration workflows.
- Provides options for selectively disabling formatting rules.
Website: github.com/lkrms/pretty-php
Support:
Developer: Luke Arms
License: MIT License
pretty-php is written in PHP. Learn PHP with our recommended free books and free tutorials.
Related Software
| PHP Code Formatters | |
|---|---|
| PHP Coding Standards Fixer | Fix coding style issues automatically |
| Mago | Fast linting, style checking and static analysis |
| PHP_CodeSniffer | Detect violations of defined coding standards |
| pretty-php | Apply consistent, opinionated source styling |
Read our verdict in the software roundup.
Explore our carefully curated directory of recommended free and open source software, covering every major software category.The directory forms part of our extensive collection of articles for Linux enthusiasts. It includes hundreds of detailed reviews, together with free and open source alternatives to proprietary software from companies such as Google, Microsoft, Apple, Adobe, IBM, Cisco, Oracle, and Autodesk. LinuxLinks also covers interesting projects worth exploring, Linux-compatible hardware, free programming books and tutorials, and much more. Know a useful free and open source Linux application that we haven’t covered? Tell us about it using our submission form. |


Please read our Comment Policy before commenting.