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.
Installation:
composer require psy/psysh --dev
Add to composer.json under require-dev to avoid deployment.
First Use:
vendor/bin/psysh
Or integrate with Laravel via php artisan tinker (uses PsySH under the hood).
First Command:
>>> $user = new App\Models\User;
>>> $user->name
help, ls, doc, edit).$_, $_E, $_S (last result, exception, stack trace).!bash commands.>>> $users = User::where('active', true)->get();
>>> $users->count()
=> 42
>>> $users->first()->toArray()
=> ["id" => 1, "name" => "John", ...]
Interactive Debugging:
>>> $order = Order::find(1);
>>> $order->items->sum('price') // Calculate total
=> 99.99
>>> $order->items->where('quantity', '>', 2) // Filter
Quick Testing:
>>> use App\Services\PaymentService;
>>> $service = new PaymentService();
>>> $service->process($order) // Test logic
Shell Integration:
>>> !ls -la // Run shell commands
>>> !composer dump-autoload // Trigger Composer tasks
>>> \Artisan::call('migrate');
>>> $mailer = app('mailer');
>>> $mailer->send(...);
>>> $user = new User();
>>> $user-> // Tab-complete methods
>>> doc User::find() // View method docs
Code Reloading (with uopz):
Edit app/Helpers.php, then in PsySH:
>>> my_helper() // Changes reflect immediately
Custom Commands:
Extend via Psy\Command\Command:
namespace App\Psy;
use Psy\Command\Command;
class MyCommand extends Command {
public function handle() {
$this->output->writeln("Hello from custom command!");
}
}
Register in .psysh.php:
return [
'commands' => [\App\Psy\MyCommand::class],
];
Configuration:
Create .psysh.php in project root:
return [
'useExperimentalReadline' => true,
'theme' => 'monokai',
];
Trust Restrictions:
.psysh.php or local autoloads.psysh --trust-project or set 'trustProject' => 'always' in config.Code Reloading Limits:
yolo for risky reloads:
>>> yolo !! // Force reload last command
Experimental Readline:
psysh --no-experimental-readline if issues arise.Magic Variables Overwrite:
$_ (last result) is overwritten by new expressions.$_E (exception) or $_S (stack trace) for debugging.Inspect Stack Traces:
>>> $_S // View full stack trace
>>> $_E->getTraceAsString() // Exception trace
Enable Verbose Mode:
>>> config('verbosity', 2) // Increase verbosity
Clear Screen:
>>> cls // Clear terminal (or Ctrl+L)
History Navigation:
Ctrl+R for reverse search.Up/Down to select.Custom Themes:
Psy\Theme\Theme or use existing themes (e.g., monokai)..psysh.php:
'theme' => 'custom-theme',
Output Formatting:
Psy\Output\OutputFormatter for custom rendering.'compactOutput' => false,
Clipboard Integration:
'clipboardCommand' => 'pbcopy', // macOS
'useOsc52Clipboard' => true, // SSH terminals
>>> $result = some_function();
>>> copy // Copies $result to clipboard
Large Data Dumping:
--no-pager to avoid pagination:
psysh --no-pager
array_slice():
>>> (new Collection($users))->slice(0, 10)->toArray()
Experimental Readline Overhead:
'useExperimentalReadline' => false,
Restricted Mode:
.psysh.php and local autoloads.--trust-project or set 'trustProject' => 'always'.CVE-2026-25129:
Edit and Reload:
>>> edit User // Opens User.php in editor
>>> // Make changes, save, and switch back to PsySH
>>> $user = new User(); // Reloaded changes
Shell Aliases:
Add to ~/.bashrc:
alias psyl='vendor/bin/psysh --trust-project'
Tab Completion:
@method in docblocks).>>> $user-> // Tab-completes magic methods like `offsetGet`
Semicolon Suppression:
>>> $result = some_function(); // Returns $result
>>> some_function(); // Suppresses return (v0.12.22+)
How can I help you explore Laravel packages today?