leofeyer / optimize-native-functions-fixer
Prefixes native PHP functions which can be replaced with opcodes by the OPcache.
Installs: 5 420
Dependents: 14
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^5.6|^7.0
- friendsofphp/php-cs-fixer: ^2.6
Requires (Dev)
- phpunit/phpunit: ^5.7.27
This package is auto-updated.
Last update: 2022-02-01 13:12:10 UTC
README
This package is no longer needed as the feature is now available in
PHP-CS-Fixer. Use the native_function_invocation
fixer with the
@compiler_optimized
option.
Optimize Native Functions Fixer
About
This custom PHP-CS-Fixer fixer prefixes native PHP functions which can be replaced with opcodes by the OPcache.
class MyClass { public function isArray($var): bool { return \is_array($var); } }
See this pull request to learn how prefixing an optimizable PHP function made the Symfony DI container 783ms faster. And see this pull request if you want to learn more about how the optimization works.
Installation
Add the package via Composer:
php composer.phar require leofeyer/optimize-native-functions-fixer --dev
Configuration
Modify your .php_cs
or .php_cs.dist
file as follows:
return PhpCsFixer\Config::create() ->setRules([ // … 'LeoFeyer/optimize_native_functions' => true, ]) ->registerCustomFixers([ new LeoFeyer\PhpCsFixer\OptimizeNativeFunctionsFixer() ]) ->setRiskyAllowed(true)
Other options
If you do not like prefixing native functions, you can also import them with a
use
statement (PHP 7 only).
use function is_array; class MyClass { public function isArray($var): bool { return is_array($var); } }