phplint
PHPLint is a high-performance syntax validation tool for PHP that provides rapid syntax checking without code execution. It serves as an essential first line of defense for catching PHP syntax errors and parse issues.
Key Features:
- Fast Syntax Validation: Lightning-fast PHP syntax checking without executing code for safe validation
- Parallel Processing: Multi-threaded scanning that efficiently handles large codebases
- Comprehensive Error Detection: Catches syntax errors, parse errors, and fundamental PHP language issues
- Multiple PHP Versions: Supports validation against different PHP versions to ensure compatibility
- Batch Processing: Validates entire directories and project structures efficiently
- SARIF Support: Modern report formats for seamless integration with development tools and platforms
- Memory Efficient: Minimal memory footprint for scanning large PHP projects
- Configurable Scanning: Flexible file inclusion/exclusion patterns and custom validation rules
phplint documentation
- Version in MegaLinter: 9.6.2
- Visit Official Web Site
- See How to configure phplint rules
- If custom
.phplint.yml
config file isn't found, .phplint.yml will be used
- If custom
Configuration in MegaLinter
- Enable phplint by adding
PHP_PHPLINT
in ENABLE_LINTERS variable - Disable phplint by adding
PHP_PHPLINT
in DISABLE_LINTERS variable
Variable | Description | Default value |
---|---|---|
PHP_PHPLINT_ARGUMENTS | User custom arguments to add in linter CLI call Ex: -s --foo "bar" |
|
PHP_PHPLINT_COMMAND_REMOVE_ARGUMENTS | User custom arguments to remove from command line before calling the linter Ex: -s --foo "bar" |
|
PHP_PHPLINT_FILTER_REGEX_INCLUDE | Custom regex including filter Ex: (src\|lib) |
Include every file |
PHP_PHPLINT_FILTER_REGEX_EXCLUDE | Custom regex excluding filter Ex: (test\|examples) |
Exclude no file |
PHP_PHPLINT_CLI_LINT_MODE | Override default CLI lint mode - file : Calls the linter for each file- list_of_files : Call the linter with the list of files as argument- project : Call the linter from the root of the project |
list_of_files |
PHP_PHPLINT_FILE_EXTENSIONS | Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all filesEx: [".py", ""] |
[".php"] |
PHP_PHPLINT_FILE_NAMES_REGEX | File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files Ex: ["Dockerfile(-.+)?", "Jenkinsfile"] |
Include every file |
PHP_PHPLINT_PRE_COMMANDS | List of bash commands to run before the linter | None |
PHP_PHPLINT_POST_COMMANDS | List of bash commands to run after the linter | None |
PHP_PHPLINT_UNSECURED_ENV_VARIABLES | List of env variables explicitly not filtered before calling PHP_PHPLINT and its pre/post commands | None |
PHP_PHPLINT_CONFIG_FILE | phplint configuration file nameUse LINTER_DEFAULT to let the linter find it |
.phplint.yml |
PHP_PHPLINT_RULES_PATH | Path where to find linter configuration file | Workspace folder, then MegaLinter default rules |
PHP_PHPLINT_DISABLE_ERRORS | Run linter but consider errors as warnings | false |
PHP_PHPLINT_DISABLE_ERRORS_IF_LESS_THAN | Maximum number of errors allowed | 0 |
PHP_PHPLINT_CLI_EXECUTABLE | Override CLI executable | ['phplint'] |
MegaLinter Flavors
This linter is available in the following flavors
Flavor | Description | Embedded linters | Info | |
---|---|---|---|---|
![]() |
all | Default MegaLinter Flavor | 127 | |
cupcake | MegaLinter for the most commonly used languages | 88 | ||
php | Optimized for PHP based projects | 55 |
Behind the scenes
How are identified applicable files
- File extensions:
.php
How the linting is performed
- phplint is called once with the list of files as arguments (
list_of_files
CLI lint mode)
Example calls
phplint myfile.php
phplint mydir
phplint mydir myfile.php
phplint mydir -vvv
Help content
Description:
Files syntax check only
Usage:
lint [options] [--] [<path>...]
Arguments:
path Path to file or directory to lint (default: working directory)
Options:
--exclude=EXCLUDE Path to file or directory to exclude from linting (multiple values allowed)
--extensions=EXTENSIONS Check only files with selected extensions (multiple values allowed)
-j, --jobs=JOBS Number of paralleled jobs to run
-c, --configuration=CONFIGURATION Read configuration from config file [default: ".phplint.yml"]
--no-configuration Ignore default configuration file (.phplint.yml)
--cache=CACHE Path to the cache directory (Deprecated option, use "cache-dir" instead)
--cache-dir=CACHE-DIR Path to the cache directory
--cache-ttl=CACHE-TTL Limit cached data for a period of time (>0: time to live in seconds) [default: 3600]
--no-cache Ignore cached data
-p, --progress=PROGRESS Show the progress output
--no-progress Hide the progress output
-o, --output=OUTPUT Generate an output to the specified path (default: standard output)
--format=FORMAT Format of requested reports (multiple values allowed)
-w, --warning Also show warnings
--memory-limit=MEMORY-LIMIT Memory limit for analysis
--ignore-exit-code Ignore exit codes so there are no "failure" exit code even when no files processed
--bootstrap=BOOTSTRAP A PHP script that is included before the linter run
-h, --help Display help for the given command. When no command is given display help for the lint command
--silent Do not output any message
-q, --quiet Only errors are displayed. All other output is suppressed
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Installation on mega-linter Docker image
- Dockerfile commands :
# Parent descriptor install
RUN update-alternatives --install /usr/bin/php php /usr/bin/php84 110
COPY --from=composer/composer:2-bin /composer /usr/bin/composer
ENV PATH="/root/.composer/vendor/bin:${PATH}"
ENV PHP_CS_FIXER_IGNORE_ENV=true
# Linter install
# renovate: datasource=packagist depName=overtrue/phplint
ARG PHP_OVERTRUE_PHPLINT_VERSION=9.6.2
# renovate: datasource=packagist depName=bartlett/sarif-php-converters
ARG PHP_BARTLETT_SARIF_PHP_CONVERTERS_VERSION=1.2.0
RUN GITHUB_AUTH_TOKEN="$(cat /run/secrets/GITHUB_TOKEN)" && export GITHUB_AUTH_TOKEN && composer global require overtrue/phplint:${PHP_OVERTRUE_PHPLINT_VERSION} bartlett/sarif-php-converters:${PHP_BARTLETT_SARIF_PHP_CONVERTERS_VERSION}