Run fast, zero-dependency PHP syntax validation from the terminal using php -l on individual files or recursively across entire projects.
Before running static analysis tools or unit test suites, you can instantly verify that your PHP files contain no syntax errors directly from the terminal.
The -l (lint) flag checks code syntax without executing the script:
# Check syntax of a single file
php -l app/Models/User.php
# Output: No syntax errors detected in app/Models/User.php
# Check all PHP files in project recursively (Linux/macOS)
find . -name "*.php" -exec php -l {} \;
# Check all PHP files recursively using PowerShell (Windows)
Get-ChildItem -Recurse -Filter *.php | ForEach-Object { php -l $_.FullName }
- Runs instantly with 0 external dependencies
- Catches parse errors, missing semicolons, and bracket mismatches early
- Easy addition to git pre-commit hooks and lightweight CI pipelines
Related Tips
View all tips →Match Multiple Values in a Single Match Arm in PHP
Separate multiple comma-delimited values within a single match expression arm to group identical execution branches.
Simplify Class Instantiation with Constructor Property Promotion
Combine property declarations and constructor parameter assignments in PHP 8 for concise class definitions.