
Rule native_function_invocation
ΒΆ
Add leading \
before function invocation to speed up resolving.
WarningΒΆ
Using this rule is riskyΒΆ
Risky when any of the functions are overridden.
ConfigurationΒΆ
exclude
ΒΆ
List of functions to ignore.
Allowed types: array
Default value: []
include
ΒΆ
List of function names or sets to fix. Defined sets are @internal
(all
native functions), @all
(all global functions) and @compiler_optimized
(functions that are specially optimized by Zend).
Allowed types: array
Default value: ['@compiler_optimized']
scope
ΒΆ
Only fix function calls that are made within a namespace or fix all.
Allowed values: 'all'
and 'namespaced'
Default value: 'all'
strict
ΒΆ
Whether leading \
of function call not meant to have it should be removed.
Allowed types: bool
Default value: true
ExamplesΒΆ
Example #1ΒΆ
Default configuration.
--- Original
+++ New
<?php
function baz($options)
{
- if (!array_key_exists("foo", $options)) {
+ if (!\array_key_exists("foo", $options)) {
throw new \InvalidArgumentException();
}
return json_encode($options);
}
Example #2ΒΆ
With configuration: ['exclude' => ['json_encode']]
.
--- Original
+++ New
<?php
function baz($options)
{
- if (!array_key_exists("foo", $options)) {
+ if (!\array_key_exists("foo", $options)) {
throw new \InvalidArgumentException();
}
return json_encode($options);
}
Example #3ΒΆ
With configuration: ['scope' => 'all']
.
--- Original
+++ New
<?php
namespace space1 {
- echo count([1]);
+ echo \count([1]);
}
namespace {
- echo count([1]);
+ echo \count([1]);
}
Example #4ΒΆ
With configuration: ['scope' => 'namespaced']
.
--- Original
+++ New
<?php
namespace space1 {
- echo count([1]);
+ echo \count([1]);
}
namespace {
echo count([1]);
}
Example #5ΒΆ
With configuration: ['include' => ['myGlobalFunction']]
.
--- Original
+++ New
<?php
-myGlobalFunction();
+\myGlobalFunction();
count();
Example #6ΒΆ
With configuration: ['include' => ['@all']]
.
--- Original
+++ New
<?php
-myGlobalFunction();
-count();
+\myGlobalFunction();
+\count();
Example #7ΒΆ
With configuration: ['include' => ['@internal']]
.
--- Original
+++ New
<?php
myGlobalFunction();
-count();
+\count();
Example #8ΒΆ
With configuration: ['include' => ['@compiler_optimized']]
.
--- Original
+++ New
<?php
$a .= str_repeat($a, 4);
-$c = get_class($d);
+$c = \get_class($d);
Rule setsΒΆ
The rule is part of the following rule sets:
@PhpCsFixer:risky with config:
['include' => ['@compiler_optimized'], 'scope' => 'namespaced', 'strict' => true]
@Symfony:risky with config:
['include' => ['@compiler_optimized'], 'scope' => 'namespaced', 'strict' => true]
Source classΒΆ
PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer