Prerequisites
Before you begin, make sure you have:- PHP 7.4 or later installed
- PsySH installed (see Installation)
Starting PsySH
Try some PHP code
Start typing PHP code at the prompt:PsySH evaluates each expression and shows you the return value.
Essential Commands
Here are the most commonly used PsySH commands:help
Show all available commands and their usage
ls
List variables, functions, classes, and more
doc
Show documentation for functions, classes, and methods
show
Display the source code for a function or class
Exploring Code
PsySH excels at code introspection. Let’s explore a class:Debugging with \Psy\debug()
The real power of PsySH comes from debugging your running application. Add a debug breakpoint anywhere in your code:- Inspect
$order,$item, and$total - Modify variables to test different scenarios
- Call functions to test behavior
- Continue execution when ready
Two-Way Debugging
Useextract() to modify variables in your running code:
Quick Debugging with eval(\Psy\sh())
For a one-liner debug breakpoint, use:Working with APIs
PsySH is perfect for testing APIs and exploring libraries:Tips for Productivity
Use command history
Use command history
Press the Up arrow to cycle through previous commands. Your history is saved between sessions.Search history with:
Tab completion
Tab completion
Press Tab to auto-complete variable names, function names, and class names:
Magic variables
Magic variables
PsySH provides special variables:
$_- The result of the last expression$_e- The last exception thrown$__out- Captured output from the last command
Debugging exceptions
Debugging exceptions
When an exception is thrown, use the
wtf command to see the stack trace:Next Steps
REPL Basics
Learn more about using the REPL effectively
Commands
Explore all available commands
Configuration
Customize PsySH to your preferences
Debugging Guide
Master debugging techniques