leofeyer/optimize-native-functions-fixer

This package is abandoned and no longer maintained. No replacement package was suggested.

Prefixes native PHP functions which can be replaced with opcodes by the OPcache.

Maintainers

👁 leofeyer

Package info

github.com/leofeyer/optimize-native-functions-fixer

pkg:composer/leofeyer/optimize-native-functions-fixer

Statistics

Installs: 5 607

Dependents: 14

Suggesters: 0

Stars: 3

Open Issues: 0

1.1.1 2018-03-02 13:15 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 9a6a9060cfe5122a2040542f6ed04062b7564e5e

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);
 }
}