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.
App\, Illuminate\) and reliance on OPcache makes this tool a natural fit. The package’s focus on reducing namespace resolution overhead directly addresses Laravel’s performance bottlenecks, particularly in:
resolve() calls or facades (\Cache::get()) could benefit from FQN optimizations.Str::of() vs. str_of()).collect(), route()), which could conflict with user-defined namespaces.post-install-cmd, post-update-cmd) provides a seamless integration point. The tool’s CLI interface aligns with Laravel’s Artisan command philosophy.require-dev avoids production bloat, adhering to Laravel’s dependency management best practices.strlen function in App\Utils).--dry-run mode first and validate with git diff.app/Utils) via CLI flags.app/ structure to scope changes (e.g., php bin/php_backslasher fix app --exclude=app/Utils).match expressions, or attributes).composer install (5–30s depending on codebase size), potentially slowing CI/CD.composer.json scripts only for production-like environments).call_user_func('strlen'), eval(), or create_function()).eval() or create_function() via .backslasherignore (if supported).app/ and config/ (user code) or include vendor/ (risk of breaking third-party packages)?app/ and config/; add --include-vendor only if benchmarking shows significant gains in third-party packages (e.g., laravel/framework).php artisan tinker --bench) or tools like Blackfire to measure OPcache hit rates before/after.CONTRIBUTING.md.fully_qualified_strict_types or custom rules achieve similar goals with lower risk?composer install to avoid slowing local development.composer.json script infrastructure for seamless integration. Example:
"scripts": {
"post-install-cmd": [
"@php_backslasher"
],
"php_backslasher": "php bin/php_backslasher fix app config --exclude=app/Utils,app/Exceptions"
}
// app/Console/Commands/BackslasherFixCommand.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class BackslasherFixCommand extends Command
{
protected $signature = 'backslasher:fix {--dir= : Directory to fix}';
public function handle()
{
$this->call('vendor:publish', ['--tag' => 'backslasher']);
$this->info('Running php_backslasher...');
$this->call('exec', ['php bin/php_backslasher fix ' . ($this->option('dir') ?: 'app config')]);
}
}
# .github/workflows/backslasher.yml
jobs:
backslasher:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-php@v2
- run: composer install --dev
- run: php bin/php_backslasher fix app config --dry-run | git diff
php.ini (critical for performance gains)."scripts": {
"post-install-cmd": [
"php bin/php_backslasher fix app",
"@php-cs-fixer fix"
]
}
composer install but before deploy scripts).Assessment Phase:
strlen in App\Utils).call_user_func, eval).match expressions) that may break the tool.git grep -r "function strlen" --include="*.php", git grep -r "eval".Pilot Integration:
composer require --dev nilportugues/php_backslasher zendframework/zend-code:~3
app/Http/Middleware):
php bin/php_backslasher fix app/Http/Middleware --dry-run
git diff and fix false positives manually.Gradual Rollout:
composer.json with a warning:
"scripts": {
"post-install-cmd": [
"@php_backslasher"
],
"php_backslasher": "php bin/php_backslasher fix app config --exclude=app/Utils,app/Exceptions"
}
Production Validation:
tinker --bench or Blackfire.UPGRADING.md with:
app/ and config/").How can I help you explore Laravel packages today?