What is PSR-12?
PSR-12 is the PHP Standards Recommendation for extended coding style, ratified by the PHP-FIG in 2019. It supersedes PSR-2 and adds rules for declare statements, namespace placement, return type declarations, nullable types, and short closures. The OpenFormatter PHP formatter applies PSR-12 brace placement and 4-space indentation defaults.
Which brace style does PHP use?
PSR-12 specifies a hybrid: classes, traits, interfaces, enums, and functions/methods use Allman braces (opening brace on its own line). Control structures (if, for, foreach, while, switch, try) use K&R braces (opening brace on the same line). This is unique to PHP — most other languages pick one style and stick with it. The formatter applies this hybrid by default.
Does formatting PHP change how it executes?
No. PHP is whitespace-insensitive outside string literals (single-quoted, double-quoted, and heredoc preserve their interior). The Zend engine compiles formatted and unformatted source to identical opcodes. The only exception: heredoc/nowdoc syntax requires the closing identifier to start at the beginning of the line — the formatter does not adjust those.
How are imports (use statements) ordered?
PSR-12 does not mandate a specific order, but the dominant convention (Symfony, Laravel) is: classes first, then function imports (use function), then constants (use const). Within each group, alphabetical order. PHP-CS-Fixer with the @PSR12 ruleset applies this. The online formatter preserves your existing order — it does not sort imports.
Does it format PHP 8 features?
Yes. Match expressions, named arguments (foo(x: 1)), nullable types (?string), union types (string|int), intersection types (Foo&Bar), attributes (#[Route(...)]), readonly properties, and constructor promotion are all formatted with PSR-12 conventions. The arrow function syntax (fn ($x) => $x * 2) stays on a single line.
How is this different from PHP-CS-Fixer or PHP_CodeSniffer?
PHP-CS-Fixer and PHP_CodeSniffer (phpcs/phpcbf) are full code-style fixers — they apply hundreds of rules from configurable rulesets (@PSR12, @Symfony, @Laravel), sort imports, and detect style violations. This online formatter is lighter: it normalises indentation and brace placement only, ideal for snippets pasted from documentation, Stack Overflow, or generated code. For project-wide enforcement, configure PHP-CS-Fixer in your composer.json and a pre-commit hook.
Is the PHP I paste sent to your servers?
No. Formatting runs entirely in your browser using JavaScript. Code containing database credentials, API keys, .env values, or proprietary business logic never leaves your device. Open DevTools → Network and click Format to verify.
Does it handle WordPress or Drupal coding standards?
Partially. WordPress Coding Standards use tabs, K&R-everywhere braces, and Yoda conditions — none of which match PSR-12. Drupal uses 2-space indentation. The formatter defaults to PSR-12 (4 spaces, hybrid braces). For WordPress or Drupal compliance, configure PHP_CodeSniffer with the WordPress-Core or Drupal coding standards instead.