Skip to content


php documentation

php-src - GitHub

Configuration in MegaLinter

Variable Description Default value
PHP_BUILTIN_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
PHP_BUILTIN_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
PHP_BUILTIN_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
PHP_BUILTIN_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
PHP_BUILTIN_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
PHP_BUILTIN_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_BUILTIN_PRE_COMMANDS List of bash commands to run before the linter None
PHP_BUILTIN_POST_COMMANDS List of bash commands to run after the linter None
PHP_BUILTIN_DISABLE_ERRORS Run linter but consider errors as warnings false
PHP_BUILTIN_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0

MegaLinter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 97 Docker Image Size (tag) Docker Pulls
php Optimized for PHP based projects 46 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .php

How the linting is performed

  • php is called one time by identified file

Example calls

php -l myfile.js

Help content

Usage: php [options] [-f] <file> [--] [args...]
   php [options] -r <code> [--] [args...]
   php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
   php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
   php [options] -S <addr>:<port> [-t docroot] [router]
   php [options] -- [args...]
   php [options] -a

  -a               Run as interactive shell
  -c <path>|<file> Look for php.ini file in this directory
  -n               No configuration (ini) files will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -f <file>        Parse and execute <file>.
  -h               This help
  -i               PHP information
  -l               Syntax check only (lint)
  -m               Show compiled in modules
  -r <code>        Run PHP <code> without using script tags <?..?>
  -B <begin_code>  Run PHP <begin_code> before processing input lines
  -R <code>        Run PHP <code> for every input line
  -F <file>        Parse and execute <file> for every input line
  -E <end_code>    Run PHP <end_code> after processing all input lines
  -H               Hide any passed arguments from external tools.
  -S <addr>:<port> Run with built-in web server.
  -t <docroot>     Specify document root <docroot> for built-in web server.
  -s               Output HTML syntax highlighted source.
  -v               Version number
  -w               Output source with stripped comments and whitespace.
  -z <file>        Load Zend extension <file>.

  args...          Arguments passed to script. Use -- args when first argument
                   starts with - or script is read from stdin

  --ini            Show configuration file names

  --rf <name>      Show information about function <name>.
  --rc <name>      Show information about class <name>.
  --re <name>      Show information about extension <name>.
  --rz <name>      Show information about Zend extension <name>.
  --ri <name>      Show configuration for extension <name>.

Installation on mega-linter Docker image

Example success log

Results of php linter (version 7.3.25)
See documentation on

[SUCCESS] .automation/test/php/php_good_1.php
    No syntax errors detected in .automation/test/php/php_good_1.php

[SUCCESS] .automation/test/php/php_good_2.php
    No syntax errors detected in .automation/test/php/php_good_2.php

Example error log

Results of php linter (version 7.3.25)
See documentation on

[ERROR] .automation/test/php/php_bad_1.php
    PHP Parse error:  syntax error, unexpected 'pe98y' (T_STRING) in .automation/test/php/php_bad_1.php on line 3
    Errors parsing .automation/test/php/php_bad_1.php

[ERROR] .automation/test/php/php_bad_2.php
    PHP Parse error:  syntax error, unexpected '}' in .automation/test/php/php_bad_2.php on line 15
    Errors parsing .automation/test/php/php_bad_2.php