Skip to content

UsingInclusionOnceReturnValue ​

error on by default

Group: Probable bugs · PhpStorm name: UsingInclusionOnceReturnValueInspection

include_once/require_once return the file's value only the first time; every later evaluation returns true. Code that uses that value works once and then silently breaks. Use include/require when the result matters.

Example ​

php
<?php
$routes = require_once __DIR__ . '/routes.php';
$ok = include_once $first ||
    include_once $second;
while (include_once($plugin)) {
    register((require_once $plugin));
}
require_once __DIR__ . '/bootstrap.php';
include_once('helpers.php');
$cfg = (require 'config.php');

Reported:

  • line 2: Only the first include_once/require_once returns the file's value; later ones return true.
  • line 3: Only the first include_once/require_once returns the file's value; later ones return true.
  • line 4: Only the first include_once/require_once returns the file's value; later ones return true.
  • line 5: Only the first include_once/require_once returns the file's value; later ones return true.
  • line 6: Only the first include_once/require_once returns the file's value; later ones return true.

Configure ​

In custos.json:

json
{
  "rules": {
    "UsingInclusionOnceReturnValue": {
      "enabled": false
    }
  }
}

Suppress ​

Before the statement or declaration (or the first statement of the file), either of:

php
// @custos-ignore UsingInclusionOnceReturnValue

/**
 * @noinspection UsingInclusionOnceReturnValueInspection
 */

Released under the MIT License. Rule catalogue modelled on Php Inspections (EA Extended); independent clean-room implementation.