Parenthesised Include

ID

php.include_without_parens

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Code Smell

Language

Php

Tags

code_smell, readability

Description

Reports include, include_once, require and require_once statements whose argument is wrapped in parentheses, for example include('file.php');. The recommended form is to write these constructs without parentheses: include 'file.php';.

Rationale

include, include_once, require and require_once are language constructs, not functions. The parentheses around the path are therefore not a function-call argument list — they are plain grouping around the path expression and have no effect. Writing them as include('file.php') makes the construct look like a function call, which is misleading: it suggests a return value and a normal call boundary that do not exist. The parentheses can also introduce subtle precedence surprises in expressions such as include ('a') . 'b', where the concatenation binds outside the parentheses rather than to the included path. Omitting the parentheses keeps the intent clear.

<?php
require_once ('config/bootstrap.php'); // FLAW — parenthesised, reads like a function call
include('partials/header.php');        // FLAW — parenthesised include

require_once 'config/bootstrap.php';   // OK — no parentheses
include 'partials/header.php';         // OK — no parentheses
require __DIR__ . '/vendor/autoload.php'; // OK — concatenated path, no enclosing parentheses

Remediation

Remove the parentheses around the path expression, leaving a single space after the construct name: include 'file.php';. For class definitions, prefer PSR-4 autoloading over manual includes altogether.