- How does react/partial help with Laravel + ReactPHP async callbacks?
- It lets you pre-fill arguments in async callbacks (e.g., WebSocket handlers or HTTP routes) without wrapping everything in closures. For example, bind a user ID to a callback: `$handle = bind([UserHandler::class, 'process'], $user);`—cleaner than `use ($user)` in closures.
- Can I use react/partial in Laravel middleware without ReactPHP?
- Yes! It works in synchronous middleware too. Bind request/response contexts to middleware logic (e.g., `$middleware = bind([AuthMiddleware::class, 'handle'], $user)`) to avoid manual closures or `$this->app->call()` wrappers.
- What Laravel versions and PHP requirements does react/partial support?
- No Laravel-specific dependencies—just PHP 7.1+. Works with any Laravel 5.5+ app, but async use cases (e.g., ReactPHP) require separate setup (e.g., `spatie/react` or `react/laravel`).
- How do I install react/partial in a Laravel project?
- Run `composer require react/partial:^2.0`—no Laravel-specific commands. For async use, pair it with ReactPHP (e.g., `react/http` for HTTP servers) via `spatie/react` or `react/laravel`.
- Does react/partial work with Eloquent models or controllers?
- Limited value for pure Eloquent/controllers. It shines in async contexts (e.g., custom queue workers with ReactPHP) or when replacing spaghetti closures in event listeners. For controllers, consider Laravel’s `app()->call()` instead.
- How do I debug partially applied functions in Laravel?
- Prefix bound functions (e.g., `$processOrderWithUser = bind(...)`) and log bound args at creation (e.g., `Logger::debug('Bound user ID:', $user->id)`). Stack traces may obscure origin—use naming conventions to trace back.
- Is react/partial safe for production? Any memory leak risks?
- Yes, it’s production-ready with no runtime dependencies. Test for memory leaks in long-running async contexts (e.g., WebSocket servers) by verifying closures don’t persist unintentionally. ReactPHP’s error handlers should propagate errors correctly.
- Can react/partial replace Laravel’s Closure::bindTo() or DI containers?
- For async callbacks or functional patterns, yes—it’s more concise. For dependency injection, stick with Laravel’s container. Example: Replace `$this->app->call([User::class, 'method'], $args)` with `bind([User::class, 'method'], $prefilledArg)`.
- How do I test code using react/partial in PHPUnit?
- Mock bound functions like closures but with explicit args. Example: `$bound = bind([$mock, 'handle'], $user); $this->expects($mock->handle($contents))->with($user)->once();`—verify both bound and dynamic args.
- What’s a better alternative if I’m not using ReactPHP?
- For synchronous Laravel, use `Closure::bindTo()` or Laravel’s `app()->call()`. For async, consider `amp/async-function` (Amp) or `spatie/react` (ReactPHP). `react/partial` excels only in async/event-driven code where argument binding is repetitive.