psy/psysh
PsySH is an interactive PHP REPL, runtime developer console, and debugger. Explore code, inspect variables, and run commands in a powerful shell with history, configuration, themes, and integrations—ideal for fast debugging and experimentation.
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 aligns well with:
uopz extension, PsySH can reload modified PHP files dynamically, reducing feedback loops for developers.Key Laravel Synergies:
app() helper).$request, $response, and middleware execution in real-time.psy/psysh) with zero Laravel-specific dependencies (beyond PHP 8.1+)../vendor/bin/psysh) with Laravel’s autoloader.Artisan (e.g., custom debug:repl command)..psysh.php for project-specific tweaks (e.g., aliases, themes, trust settings).| Risk Area | Mitigation Strategy |
|---|---|
| Security | Enforce trustProject: 'prompt' in CI/CD; audit .psysh.php files. |
| Compatibility | Test with PHP 8.1+ (Laravel’s LTS range). Symfony Console v7.4+ is supported. |
| Performance | Avoid heavy REPL sessions in production; use --no-pager for CLI scripts. |
| Hot Reloading | Requires uopz extension (not always available); document limitations. |
| Terminal Dependencies | Experimental readline may need terminal-specific tweaks (e.g., SSH, Windows WSL). |
php artisan psy, IDE integration)?trustProject default to 'never' in production-like environments?.psysh.php files be version-controlled (if at all)?$user = User::first())?bootstrap/app.php)?APP_ENV checks?PsySH is natively compatible with Laravel’s stack:
require-dev psy/psysh).app() and bound services.| Phase | Action | Tools/Dependencies |
|---|---|---|
| Evaluation | Install PsySH in a dev environment; compare with Laravel Tinker. | composer require-dev psy/psysh |
| Basic Integration | Add PsySH to composer.json; test standalone usage (./vendor/bin/psysh). |
bootstrap/app.php (Laravel autoloader) |
| Artisan Embedding | Create a custom Artisan command (e.g., php artisan psy). |
Illuminate\Console\Command |
| Configuration | Add .psysh.php with Laravel-specific aliases (e.g., $request = app('request')). |
Psy\Configuration |
| Advanced Features | Enable hot reloading (uopz), experimental readline, or clipboard integration. |
uopz extension, terminal support |
| Documentation | Update dev docs with PsySH workflows (e.g., debugging middleware). | Markdown, IDE snippets |
psy/psysh:^0.11 (pre-Symfony 7).uopz for hot reloading).ext-readline or ext-libedit for legacy completion (experimental readline is optional)../vendor/bin/psysh as a "PHP REPL" tool.$PSYSH_TRUST_PROJECT=always..psysh.php trust model in team environments.psy:repl command with Laravel’s service container pre-loaded.use Psy\Sh;
use Illuminate\Console\Command;
class PsyCommand extends Command {
protected $signature = 'psy:repl';
public function handle() {
(new Sh)->run();
}
}
uopz) for rapid iteration..psysh.php configuration and security best practices.^0.12) to avoid breaking changes..psysh.php files may proliferate across projects. Enforce a standard template.PSYSH_TRUST_PROJECT environment variables for CI/CD consistency.trustProject warnings. Document how to configure globally.uopz limitations (e.g., no class property changes) require education.#psysh channel in team Slack for quick troubleshooting.>>> (history) and copy (clipboard) for bug reports.--no-pager for scripts.ls $object) can be slow. Cache frequent inspections.How can I help you explore Laravel packages today?