nilportugues/php_backslasher
CLI tool that scans PHP code and prefixes internal functions/constants (plus true/false/null) with a leading backslash for faster resolution, especially with OPcache. Run php bin/php_backslasher fix to update a directory.
strlen vs. App\Helpers\strlen). Integrate with Laravel’s coding standards (e.g., PSR-12) as a pre-commit hook or CI gate.view() → \view()).# .github/workflows/laravel-ci.yml
- name: BackSlasher
run: php artisan backslasher:fix --dry-run
App\Modules\, App\Providers\).php artisan opcache:status).call_user_func('strlen'), app()->make() with strings).Cache::get() may conflict with \Cache constants).strlen in a class).php-cs-fixer with custom rules).For Executives:
"This tool automates a 1–5% performance boost for Laravel apps using OPcache by eliminating namespace lookup overhead—a free win for our [high-traffic API/microservice]. For example, converting strlen() to \strlen() in Laravel’s request validation pipeline could reduce TTFB by ~10ms at scale, directly supporting our [performance SLOs]. It’s a zero-code-change upgrade with a one-time setup cost (CI integration) and minimal risk, ideal for our [legacy/Laravel 8] codebase."
For Engineering (Laravel Team): *"php_backslasher solves two Laravel-specific pain points:
array_map, json_encode). This tool prepends backslashes to force FQN resolution, cutting lookup time.strlen and \strlen in Laravel apps. This enforces consistency via CI, reducing bugs like strlen shadowing custom helpers.Proposal:
composer.json as a dev dependency with a CI gate:
"scripts": {
"post-install-cmd": [
"@php_backslasher fix app"
]
}
php artisan tinker --bench.For Developers: *"This CLI tool auto-fixes PHP namespace issues in Laravel codebases by adding backslashes to internal functions/constants. Use it like this:
composer require --dev nilportugues/php_backslasher
php bin/php_backslasher fix app/Http
Why?
\strlen vs. strlen.strlen is defined in a class.config/ files (e.g., env('APP_DEBUG') → \env('APP_DEBUG')).Caveats:
vendor/ by default (risk of breaking third-party packages).git diff to review changes:
php bin/php_backslasher fix app --dry-run | git apply --check
```"*
How can I help you explore Laravel packages today?