php -l and lint-php.sh

Contents
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:

  1. After the PHPCBF safe-sniff pass (1050 errors in 113 files) and the FileHeader pass (1735 errors in 1734 files): linted: 5105, failures: 0.
  2. 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

Related articles
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

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: