This page covers additional PsySH commands that help with session management and general usage.
help Command
Display help information about PsySH commands.
Syntax
Alias
Arguments
The name of a command to get help for. If omitted, shows a list of all available commands.
Usage Examples
List All Commands
doc Read the documentation for an object, class, constant, method or property.
Aliases: rtfm, man
show Show the code for an object, class, constant, method or property.
ls List local, instance or class variables, methods and constants.
Aliases: dir
dump Dump an object or primitive.
history Show the Psy Shell history.
Aliases: hist
... (more commands)
Get Help for Specific Command
>>> help doc
>>> help ls
>>> ? show
Usage:
doc [options] [--] [<target>]
Arguments:
target Function, class, instance, constant, method or property to document.
Options:
-a, --all Show documentation for superclasses as well.
--update-manual Download and install the latest PHP manual
Help:
Read the documentation for an object, class, constant, method or property.
e.g.
>>> doc preg_replace
>>> doc Psy\Shell
Tips
Use ? as a quick shortcut:
If you try to get help for a non-existent command, PsySH suggests using doc instead:>>> help array_map
CommandNotFoundException: Command "array_map" not found.
To read PHP documentation, use doc array_map
exit Command
Exit the PsySH session and return to the caller.
Syntax
Aliases
Usage Examples
Behavior
In Standalone Mode
When running PsySH from the command line:
$ psysh
>>> exit
Goodbye
$ # Back to shell
Returns you to your system shell.
As a Debugger
When using \Psy\debug() as a breakpoint:
function processData($data) {
\Psy\debug();
return transform($data);
}
>>> exit
Goodbye
# Code continues executing
Execution resumes after the debug point.
In Nested Shells
If you’ve opened a new shell within PsySH:
>>> $shell = new Psy\Shell()
>>> $shell->run()
>>> exit # Exits the nested shell
>>> exit # Exits the outer shell
Keyboard Shortcuts
You can also exit using:
- Ctrl+D (EOF) - On Unix/Linux/macOS
- Ctrl+Z then Enter - On Windows
Ctrl+D is often faster than typing exit:>>> # Press Ctrl+D
Goodbye
clear Command
Clear the PsySH screen.
Syntax
Usage
The terminal screen is cleared, and you get a fresh prompt.
How It Works
The clear command sends ANSI escape sequences to clear the terminal:
ESC[2J - Clear entire screen
ESC[0;0f - Move cursor to 0,0
Alternative Methods
Keyboard Shortcut
If your PHP has readline support:
- Ctrl+L - Clear screen (on most terminals)
>>> # Press Ctrl+L to clear
Ctrl+L is usually faster and works in most readline-enabled applications.
Manual Terminal Clear
You can also use your terminal’s clear command before starting PsySH:
When to Use
- Cluttered output - After dumping large objects or running many commands
- Fresh start - When beginning a new debugging session
- Privacy - Before sharing your screen
- Focus - To remove distractions
>>> dump $huge_object
[... 1000 lines of output ...]
>>> ls
[... more output ...]
>>> # Screen is cluttered
>>> clear
>>> # Clean screen, ready to work
Additional Utility Commands
PsySH includes several additional commands for advanced use cases:
sudo Command
Execute PHP code while bypassing visibility restrictions (private/protected access).
Syntax
Usage
>>> class Secret {
... private function whisper() { return "secret"; }
... }
>>> $s = new Secret()
>>> $s->whisper()
PHP error: Call to private method Secret::whisper()
>>> sudo $s->whisper()
=> "secret"
The sudo command rewrites your code to bypass PHP’s visibility restrictions, allowing you to call private and protected methods or access private and protected properties.
This is useful for debugging and testing, but should not be used in production code.
buffer Command
Show or clear the contents of the code input buffer.
Syntax
Alias
Options
Clear the current code buffer
Usage
Show the current buffer (useful when writing multi-line code):
>>> function test() {
...
>>> buffer
1: function test() {
Clear the buffer:
>>> function test() {
...
>>> buffer --clear
1: function test() {
>>> # Buffer cleared
parse Command
Parse PHP code and display the abstract syntax tree (AST).
Syntax
Usage
>>> parse echo "hello"
=> [
PhpParser\Node\Stmt\Echo_ {
exprs: [
PhpParser\Node\Scalar\String_ {
value: "hello",
},
],
},
]
This command is useful for understanding how PHP’s parser interprets your code. It uses the nikic/php-parser library internally.
Use parse to debug complex expressions or understand operator precedence.
timeit Command
Profile code execution time.
Syntax
timeit [-n|--num <iterations>] <code>
Options
Number of iterations to run (default: 1)
Usage
Time a single execution:
>>> timeit sleep(1)
Command took 1.000234 seconds to complete.
Run multiple iterations to get average timing:
>>> timeit -n1000 md5('test')
Command took 0.000023 seconds on average (0.000022 median; 0.023456 total) to complete.
Use timeit -n with a high iteration count to get accurate performance measurements for fast operations.
version Command
Display the current PsySH version.
Syntax
Usage
>>> version
Psy Shell v0.12.20 (PHP 8.2.0 — cli) by Justin Hileman
throw-up Command
Throw an exception or error out of the PsySH shell.
Syntax
Usage
Throw the last exception:
>>> throw new Exception("test")
Exception: test
>>> throw-up
# Exception is thrown outside of PsySH
Throw a new exception:
>>> throw-up new RuntimeException("error")
# RuntimeException is thrown outside of PsySH
Throw with a string message:
>>> throw-up "Something went wrong!"
# Exception with message is thrown
This command exits PsySH and throws the exception to the calling code. Use it when you want to propagate an error out of a debug session.
yolo Command
Execute code while bypassing reloader safety checks.
Syntax
Usage
When the reloader shows warnings about conditionally defined functions or other risky operations, use yolo to force execution:
>>> if ($condition) { function helper() {} }
Warning: Skipped conditional: if (...) { function helper() ... }
>>> yolo !!
=> null
# Code executed despite warning
The !! syntax repeats the last command (like in bash).
The “reloader” is PsySH’s feature that allows you to re-define functions and classes. Use yolo when you understand the risks and want to proceed anyway.
Common Workflows
Help → Explore → Clean
>>> help # See available commands
>>> doc DateTime # Learn about a class
>>> dump $object # Inspect something
>>> clear # Clean up
>>> exit # Leave
Debug → Fix → Exit
// Code hits \Psy\debug()
>>> whereami # Where am I?
>>> ls # What's available?
>>> dump $var # What's wrong?
>>> $var = 'fixed' # Test fix
>>> exit # Continue execution
Quick Reference
>>> ? # Quick help
>>> ? doc # Help on 'doc' command
>>> doc array_map # Read PHP docs
>>> clear # Clean screen
>>> q # Quick exit
Tips & Shortcuts
Keyboard shortcuts are faster:
Ctrl+D instead of exit
Ctrl+L instead of clear
? instead of help
Chain help exploration:>>> help # See all commands
>>> help ls # Learn about 'ls'
>>> ls DateTime # Try it out
>>> doc DateTime # Read more
Use aliases for speed:>>> q # Faster than 'exit'
>>> ? # Faster than 'help'
>>> hist # Faster than 'history'
See Also