PHP's evolution from scripting language to enterprise framework brought PSR standards — the community-agreed formatting rules that make PHP codebases consistent across frameworks like Laravel, Symfony, and WordPress. PSR-12 is the current standard, and adhering to it signals professional PHP development.
What Is PHP Formatter?
PHP formatting applies PSR-12 rules: opening braces on new lines for classes/methods, 4-space indentation, use statement ordering, and visibility declarations. Our PHP Formatter transforms any PHP code to PSR-12 compliance.
How to Use PHP Formatter on DevToolHub
- Open the PHP Formatter tool on DevToolHub — no signup required.
- Paste or enter your input data in the left panel.
- See the result instantly in the output panel.
- Copy the result or download it as a file.
PSR-12 Class Formatting
See the standard structure for a PHP class:
<?php
// Before
class UserService {
private $repo;
public function __construct(UserRepository $repo){$this->repo=$repo;}
public function findActive():array{return $this->repo->findBy(["status"=>"active"]);}
}
// After (PSR-12)
class UserService
{
private UserRepository $repo;
public function __construct(UserRepository $repo)
{
$this->repo = $repo;
}
public function findActive(): array
{
return $this->repo->findBy([
"status" => "active",
]);
}
}Pro Tips
- Opening braces go on the next line for classes and methods, same line for control structures
- Use PHP CS Fixer or PHP_CodeSniffer in CI to enforce PSR-12 automatically
- Declare strict_types=1 at the top of every file for type safety
- Order use statements alphabetically and group by type (classes, functions, constants)
When You Need This
- Formatting Laravel and Symfony code to framework conventions
- Standardizing WordPress plugin code to PSR-12
- Cleaning up legacy PHP code during modernization projects
- Preparing PHP code examples for technical documentation
Free Tools Mentioned in This Article