Adds all PHP internal functions to its namespace by adding backslash to them. Improves the application's performance when OPCache is on.
Tool to add all PHP internal functions and constants to its namespace by adding backslash to them.
Function resolution without the backslash forces the PHP internals to verify for each function call if function or constant belongs to current namespace or the global namespace. With the backslash PHP does not check the current namespace and therefore execution is faster when using OP Cache.
Idea from Nikita Popov talk:
Use Composer to install the package:
$ composer require --dev nilportugues/php_backslasher
$ php bin/php_backslasher fix <path/to/directory>
Works for functions in conditional statements, negative conditionals, placed in an array as key or value and any other normal use. Also adds a backslash to defined constants and true, false and null values.
echo strlen('Hello World'); var_dump(null); var_dump(false); echo DIRECTORY_SEPARATOR; return true; // becomes: echo \strlen('Hello World'); \var_dump(\null); \var_dump(\false); echo \DIRECTORY_SEPARATOR; return \true;
Contributions to the package are always welcome!
- Report any bugs or issues you find on the issue tracker.
- You can grab the source code at the package's Git repository.
Get in touch with me using one of the following means:
The code base is licensed under the MIT license.