php -l and lint-php.sh
| Install | |
| Simple example | |
| Complex usage | |
| What it fixed in src/ |
Install
Nothing to install. php -l ships with every PHP interpreter. The wrapper scripts/lint-php.sh needs only the project Docker image, exactly like the other linters:
php -l src/dev/php/array.php ./scripts/lint-php.sh --help
Simple example
Lint one file after editing it:
php -l src/ru/qa/.php/Rblock.php
No syntax errors detected in src/ru/qa/.php/Rblock.php
Whole-tree syntax check from container/:
./scripts/lint-php.sh
Complex usage
Same selection flags as lint-static.sh: explicit paths, staged changes, or the whole tree. Read-only runs never modify code:
./scripts/lint-php.sh --files src/ru/qa/.php/Rblock.php src/dev/php/linters/ ./scripts/lint-php.sh --staged ./scripts/lint-php.sh --all
php -l is also the safety gate of wrap-long-lines.sh --fix: every file the wrapper touches must pass php -l afterwards, otherwise the file is restored byte-for-byte and reported as failed.
What it fixed in src/
Strictly speaking php -l fixes nothing — it only reports. But it certified the two mass cleanups below:
- After the PHPCBF safe-sniff pass (1050 errors in 113 files) and the FileHeader pass (1735 errors in 1734 files): linted: 5105, failures: 0.
- After renaming 7 snake_case methods in src/ru/qa/.php/Rblock.php (show_rblock to showRblock and friends) plus 12 callers: no syntax errors in any touched file.
php -l prints Deprecated notices it does not fail on, for example optional parameters declared before required ones in Rblock.php and Page.php. Those are left alone: fixing them is a refactor, not a syntax fix.
Article author: Andrei Olegovich
| Development with PHP | |
| PHP linters we use | |
| php -l and lint-php.sh | |
| PHPCS: PHP CodeSniffer | |
| phpcs.xml ruleset file | |
| PHPCBF: fix style automatically | |
| wrap-long-lines.sh | |
| PHPStan and Psalm |