psy/psysh
PsySH is an interactive PHP REPL and runtime developer console for debugging and exploring code. Inspect variables, run snippets, and get contextual help in a powerful shell, with configuration, themes, and integrations available.
PsySH is a runtime REPL (Read-Eval-Print Loop) for PHP, designed to provide an interactive debugging and development environment. For a Laravel-based application, it fits well as:
tinker (Laravel’s built-in REPL) with advanced features like syntax-aware autocompletion, multi-line editing, and experimental readline.dd(), dump(), and log()) by allowing live inspection and manipulation of objects, variables, and application state.Key Strengths:
✅ Deep PHP integration – Works seamlessly with Laravel’s dependency injection, service container, and Eloquent models.
✅ Advanced autocompletion – Syntax-aware, type-aware, and runtime-value-aware completions (e.g., $user-> suggests actual methods/properties).
✅ Multi-line editing & syntax highlighting – Improves productivity for complex queries or debugging sessions.
✅ Hot code reloading (with uopz) – Allows live modification of functions/methods without restarting the REPL.
✅ Security improvements – Restricted Mode prevents arbitrary code execution from untrusted .psysh.php files (critical for shared environments).
Potential Gaps:
⚠ Not a production tool – PsySH is not designed for server-side execution; it’s strictly a development aid.
⚠ Terminal-dependent – Some features (e.g., clipboard integration, experimental readline) require specific terminal support.
⚠ Learning curve – While intuitive, advanced features (e.g., yolo for unsafe reloading, custom exception details) may require documentation.
PsySH integrates with Laravel via:
require psy/psysh)..psysh.php for project-specific settings).Laravel-Specific Considerations:
$app->make('UserRepository')).Route::current() or app('router').event(new UserRegistered($user))).Example Workflow:
# Start PsySH in a Laravel project
php artisan psy
# Inspect a user
$user = App\Models\User::find(1);
$user->posts()->count();
# Modify a model method live (with uopz)
yolo $user->getFullName() => $user->name . ' ' . $user->last_name;
Feasibility Score: 9/10
| Risk Area | Severity | Mitigation |
|---|---|---|
| Security (CVE-2026-25129) | High | Already patched in v0.12.19+. Enforce trustProject: 'prompt' in CI/CD. |
| Terminal Dependency | Medium | Document fallback to ext-readline for unsupported terminals. |
Hot Reloading (uopz) |
Medium | Warn users about uopz requirement; provide alternatives (e.g., opcache_reset()). |
| Laravel-Specific Quirks | Low | Test with Laravel 10/11; verify compatibility with Symfony 7.x. |
| Memory Leaks | Low | Monitor long-running sessions; use --no-pager for large outputs. |
Critical Path:
Replacement Strategy
tinker if we switch?Configuration Management
.psysh.php be auto-generated in new Laravel projects with sensible defaults?CI/CD & Testing
User Adoption
Long-Term Maintenance
laravel: namespace commands)?PsySH is optimized for:
Compatibility Matrix:
| Component | Compatibility | Notes |
|---|---|---|
| Laravel Artisan | ✅ Full | Works as a drop-in replacement for tinker. |
| Eloquent | ✅ Full | Full query builder and model introspection. |
| Livewire/Inertia | ✅ Partial | Can inspect state but not trigger UI events. |
| Queues/Jobs | ✅ Partial | Can dispatch jobs but not simulate workers. |
| API Testing | ❌ No | Not a replacement for Pest/HTTP tests. |
composer.json:
composer require psy/psysh --dev
tinker to psy (optional):
alias tinker='php artisan psy'
artisan command:
vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php to include PsySH as a default REPL..psysh.php template:
// config/psysh.php (auto-generated)
return [
'trustProject' => 'prompt',
'useExperimentalReadline' => env('PSYSH_EXPERIMENTAL_READLINE', false),
'theme' => 'laravel', // Custom theme
];
;; for semicolon suppression, yolo for unsafe reloads).tinker in Laravel 12+ with a warning:
php artisan tinker
# Warning: `tinker` is deprecated. Use `php artisan psy` instead.
| Feature | PsySH Support | Laravel Tinker Support | Notes |
|---|---|---|---|
| Autocompletion | ✅ Advanced | ✅ Basic | PsySH supports type-aware completions. |
| Multi-line Editing | ✅ Yes | ❌ No | Press Enter mid-statement. |
| Hot Reloading | ✅ (with uopz) |
❌ No | Requires extension. |
| Clipboard Integration | ✅ Yes | ❌ No | Copy results with copy $_. |
| Custom Themes | ✅ Yes | ❌ No | Supports laravel theme. |
| Security (Restricted Mode) | ✅ Yes | ❌ No | Prevents untrusted .psysh.php. |
Fallback Plan:
ext-readline), fall back to a basic REPL with a warning.How can I help you explore Laravel packages today?