Format and beautify PHP code — add proper indentation, normalise spacing around operators and produce clean, readable PHP following PSR-2 style conventions.
Enter your figures and click Calculate to see your results.
Paste your PHP code, choose to format or analyze stats, then select indent size — PSR-2 style is the default.
Click the Format button. Your code is processed instantly — all formatting runs in your browser with no data sent to servers.
The formatted output appears on the right. Click Copy to grab it, or Download to save as a file. Statistics like size reduction and line count are shown automatically.
PSR-2 is a PHP coding style standard from the PHP-FIG (Framework Interoperability Group). It defines: 4 spaces for indentation (no tabs), LF line endings, opening braces on same line for control structures but new line for classes and functions, space after control structure keywords, and more. PHP-CS-Fixer and PHP_CodeSniffer enforce PSR-2 (and the updated PSR-12) automatically. Following PSR ensures your code is consistent with the PHP ecosystem.
PSR-12 (released 2019) extends and supersedes PSR-2. It adds rules for: nullable types (?string), union types (string|int), return types, typed properties, match expressions, named arguments, and other PHP 7.1+ features. PSR-12 is now the recommended standard. PHP-CS-Fixer and PHP_CodeSniffer both support PSR-12 rules. Most modern PHP frameworks (Laravel, Symfony) use PSR-12 as their base coding standard.
PHP supports type declarations for parameters, return types and properties: function add(int $a, int $b): int { return $a + $b; }. Available types: scalar (int, float, string, bool), compound (array, callable, iterable), special (void, null, mixed, never), union (string|int), intersection (Stringable&Countable), and nullable (?string). Strict typing (declare(strict_types=1)) makes PHP enforce types strictly rather than coercing them. Types improve IDE support, catch bugs early and serve as inline documentation.
Composer is PHP's dependency manager (equivalent to npm for JavaScript or pip for Python). It reads composer.json (dependencies list) and installs packages from Packagist (the main PHP package repository) into the vendor directory, generating an autoloader. Key commands: composer install (install from composer.lock), composer update (update packages), composer require vendor/package (add a package). The vendor directory is excluded from Git; composer.lock is committed.
An interface defines a contract (method signatures only, no implementation): interface Drawable { public function draw(): void; }. Multiple interfaces can be implemented. An abstract class can have both abstract methods (no implementation) and concrete methods (with implementation): abstract class Shape { abstract public function area(): float; public function describe(): string { return "I am a ".get_class($this); } }. Only one abstract class can be extended (PHP is single-inheritance). Use interfaces for capabilities; abstract classes for shared implementation.
Traits are a mechanism for code reuse in single-inheritance PHP. A trait is like a class fragment that can be mixed into any class: trait Timestampable { private DateTime $createdAt; public function getCreatedAt(): DateTime { return $this->createdAt; } }. Classes use traits with the use keyword. Traits can have properties, methods, and abstract methods. Multiple traits can be used in one class. They avoid the limitations of single inheritance while preventing the complexity of multiple inheritance.
PHP 8.0 introduced match — a more powerful alternative to switch. Differences: match uses strict comparison (===); switch uses loose comparison (==). match returns a value; switch does not. match throws UnhandledMatchError if no arm matches; switch falls through silently. match arms cannot fall through (no break needed). match is an expression (can be used inline). Example: $result = match($status) { 200 => "OK", 404 => "Not Found", default => "Unknown" };
Named arguments (PHP 8.0+) allow passing arguments by parameter name: array_slice(array: $users, offset: 2, length: 5, preserve_keys: true). Benefits: skip optional parameters in the middle, make function calls self-documenting, and order-independent. Named arguments work with built-in functions too: htmlspecialchars(string: $input, flags: ENT_QUOTES, encoding: "UTF-8"). They are particularly useful for functions with many optional parameters.