Skip to content

PreloadingUsageCorrectness ​

warning on by default quick-fix

Group: Probable bugs · PhpStorm name: PreloadingUsageCorrectnessInspection

In an opcache preload script, including files with require/include executes them, which can fail on unresolved dependencies (PHP bug #78918). opcache_compile_file() only compiles and caches the file, which is what a preload script usually wants.

Example ​

File preload.php:

php
<?php
require __DIR__ . '/src/Kernel.php';
include_once($base . 'helpers.php');
require_once ( 'vendor/autoload.php' );
$map = require 'classmap.php';
return include 'tail.php';
php
<?php
opcache_compile_file(__DIR__ . '/src/Kernel.php');
opcache_compile_file($base . 'helpers.php');
opcache_compile_file('vendor/autoload.php');
$map = require 'classmap.php';
return include 'tail.php';

Reported:

  • line 2: Use opcache_compile_file() in a preload script instead of require.
  • line 3: Use opcache_compile_file() in a preload script instead of include_once.
  • line 4: Use opcache_compile_file() in a preload script instead of require_once.

Configure ​

In custos.json:

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

Suppress ​

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

php
// @custos-ignore PreloadingUsageCorrectness

/**
 * @noinspection PreloadingUsageCorrectnessInspection
 */

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