Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Backslasher Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Performance Optimization for Laravel APIs: Justify adoption as part of a Laravel-specific performance roadmap, particularly for high-traffic endpoints (e.g., REST APIs, GraphQL resolvers) where OPcache overhead is measurable. Align with goals like "Reduce 95th percentile response time by 15%" by targeting namespace resolution bottlenecks in Laravel’s service container or facades.
  • Code Quality Standardization: Enforce consistent use of fully qualified names (FQNs) across Laravel teams to mitigate ambiguity in namespaced code (e.g., strlen vs. App\Helpers\strlen). Integrate with Laravel’s coding standards (e.g., PSR-12) as a pre-commit hook or CI gate.
  • Legacy Laravel Migration: Accelerate upgrades from Laravel 5.x/6.x to Laravel 8/9/10 by retroactively applying FQNs to legacy codebases, reducing manual refactoring effort for internal functions (e.g., view()\view()).
  • DevOps Automation: Embed in Laravel’s CI/CD pipeline (e.g., GitHub Actions, GitLab CI) as a pre-deploy step to catch namespace inconsistencies early. Example:
    # .github/workflows/laravel-ci.yml
    - name: BackSlasher
      run: php artisan backslasher:fix --dry-run
    
  • Build vs. Buy: Buy for Laravel teams lacking PHP parser expertise; build only if needing deeper integration (e.g., Laravel-specific IDE plugins or custom validation rules).
  • Use Cases:
    • Monolithic Laravel apps with deep namespace hierarchies (e.g., App\Modules\, App\Providers\).
    • Microservices where OPcache is critical (e.g., Laravel Octane + Swoole).
    • Shared hosting environments with OPcache enabled (common in Laravel Forge/Vapor deployments).

When to Consider This Package

  • Avoid if:
    • Your Laravel app does not use namespaces (e.g., legacy projects with global functions).
    • OPcache is disabled (verify with php artisan opcache:status).
    • The team prioritizes developer experience over micro-optimizations (e.g., startups, MVPs).
    • The codebase relies on dynamic function calls (e.g., call_user_func('strlen'), app()->make() with strings).
    • Laravel Facades are heavily used without FQNs (e.g., Cache::get() may conflict with \Cache constants).
    • The project uses custom autoloaders (e.g., non-PSR-4) that may misinterpret FQNs.
  • Look elsewhere if:
    • You need IDE integration (use PHPStorm’s "Optimize Imports" or Laravel IDE Helper).
    • The codebase includes user-defined functions/constants with the same names as PHP internals (e.g., strlen in a class).
    • You require real-time linting (consider php-cs-fixer with custom rules).
    • Laravel 10+ features (e.g., enums, attributes) introduce parsing edge cases.

How to Pitch It (Stakeholders)

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:

  1. OPcache Bottlenecks: Laravel’s service container and facades trigger namespace fallbacks for every internal function call (e.g., array_map, json_encode). This tool prepends backslashes to force FQN resolution, cutting lookup time.
  2. Codebase Drift: Teams often mix strlen and \strlen in Laravel apps. This enforces consistency via CI, reducing bugs like strlen shadowing custom helpers.

Proposal:

  • Add to composer.json as a dev dependency with a CI gate:
    "scripts": {
      "post-install-cmd": [
        "@php_backslasher fix app"
      ]
    }
    
  • Pilot on our API module (highest OPcache impact) and benchmark with php artisan tinker --bench.
  • Document in the [Laravel internals wiki] as a recommended optimization for performance-critical paths."*

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?

  • Faster Laravel: OPcache skips namespace checks for \strlen vs. strlen.
  • No More ‘Did You Mean?’: Avoids conflicts when strlen is defined in a class.
  • Works in Laravel: Handles facades, helpers, and even config/ files (e.g., env('APP_DEBUG')\env('APP_DEBUG')).

Caveats:

  • Test in a staging branch first—it’s a one-way change.
  • Exclude vendor/ by default (risk of breaking third-party packages).
  • Pair with git diff to review changes:
    php bin/php_backslasher fix app --dry-run | git apply --check
    ```"*
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky