Skip to content

DynamicCallsToScopeIntrospection ​

warning on by default PHP ≥ 7.1

Group: Language level migration · PhpStorm name: DynamicCallsToScopeIntrospectionInspection

Since PHP 7.1, functions that read or write the caller's local scope (compact, extract, func_get_args, …) refuse to run when invoked indirectly — through a variable holding their name or as a callback string. Such calls only produce a warning and do nothing useful.

Example ​

php
<?php
function collect($handler = 'func_get_args')
{
    $grab = $handler();

    $rows = array_map('extract', $input);
    call_user_func_array('\compact', ['a', 'b']);

    $reader = 'mb_parse_str';
    $reader($query, $out);

    $either = $flag ? 'extract' : 'compact';
    $either($row);

    array_filter($items);
    array_filter($items, 'trim');
    compact('grab', 'rows');
}

$top = 'get_defined_vars';
$top();

Reported:

  • line 4: 'func_get_args' reads the caller scope and cannot be invoked indirectly since PHP 7.1.
  • line 6: 'extract' reads the caller scope and cannot be invoked indirectly since PHP 7.1.
  • line 7: 'compact' reads the caller scope and cannot be invoked indirectly since PHP 7.1.
  • line 10: 'mb_parse_str' reads the caller scope and cannot be invoked indirectly since PHP 7.1.

Configure ​

In custos.json:

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

Suppress ​

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

php
// @custos-ignore DynamicCallsToScopeIntrospection

/**
 * @noinspection DynamicCallsToScopeIntrospectionInspection
 */

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