-
Notifications
You must be signed in to change notification settings - Fork 319
Commands
To run a command, enter its name at the prompt, followed by any arguments that it accepts:
>>> $a = $b = 'c'
=> "c"
>>> ls -al
Variables:
$a "c"
$b "c"
$_ "c"
>>>
In the extremely unlikely case that your command name conflicts with some PHP code you actually want to run, you can prefix your input with a semicolon to prevent commands from running:
>>> const help = 'HELP ME!'
=> true
>>> help
help Show a list of commands. Type `help [foo]` for information about [foo]. Aliases: ?
ls List local, instance or class variables, methods and constants. Aliases: list, dir
dump Dump an object or primitive.
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.
...
>>> ;help
=> "HELP ME!"
>>>
The help command will print a list of all commands currently available in PsySH, along with a short description of what each command does:
>>> help
help Show a list of commands. Type `help [foo]` for information about [foo]. Aliases: ?
ls List local, instance or class variables, methods and constants. Aliases: list, dir
dump Dump an object or primitive.
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.
...
>>>
The help command can also show more informationβincluding usage and examplesβabout a specific command:
>>> help dump
Usage:
dump [--depth DEPTH] [-a|--all] [--] <target>
Arguments:
target A target object or primitive to dump.
Options:
--depth Depth to parse (default: 10)
--all (-a) Include private and protected methods and properties.
Help:
Dump an object or primitive.
This is like var_dump but way awesomer.
e.g.
>>> dump $_
>>> dump $someVar
>>>
-
bufferβ Show (or clear) the contents of the code input buffer. -
clearβ Clear the Psy Shell screen. -
configβ Inspect or update runtime-configurable PsySH settings for the current session. -
copyβ Copy a value to the clipboard. -
docβ Read the documentation for an object, class, constant, method or property. -
dumpβ Dump an object or primitive. -
editβ Open an external editor. Afterwards, get produced code in input buffer. -
exitβ End the current session and return to caller. -
helpβ Show a list of commands. Typehelp [foo]for information about [foo]. -
historyβ Show the Psy Shell history. -
lsβ List local, instance or class variables, methods and constants. -
showβ Show the code for an object, class, constant, method or property. -
sudoβ Evaluate PHP code, bypassing visibility restrictions. -
throw-upβ Throw an exception out of the Psy Shell. -
timeitβ Profiles with a timer. -
traceβ Show the current call stack. -
whereamiβ Show where you are in the code. -
wtfβ Show the backtrace of the most recent exception. -
yoloβ Execute code, bypassing π reloader safety checks.
The config command lets you inspect and update a subset of PsySH settings at runtime for the current shell session.
>>> config list
>>> config get pager
>>> config set pager off
>>> config set semicolonsSuppressReturn double
These changes are session-local only. If you want them to persist, add them to your PsySH config file.
Runtime-configurable settings currently include verbosity, useUnicode, errorLoggingLevel, clipboardCommand, useOsc52Clipboard, colorMode, theme, pager, requireSemicolons, semicolonsSuppressReturn, useBracketedPaste, useSyntaxHighlighting, and useSuggestions.
The copy command copies a value to your clipboard.
>>> copy
>>> copy User::all()->toArray()
>>> copy new Foo()
With no arguments, copy uses the last evaluated result ($_). With an expression, it evaluates the expression and copies the exported value. Clipboard behavior can be customized with the clipboardCommand and useOsc52Clipboard config options.
The ls, doc, and show commands resolve class names using the current namespace and use statements, just like code execution does. This means you can reference classes by their short name:
>>> namespace App\Models;
>>> use Illuminate\Database\Eloquent\Model as EloquentModel;
>>> doc User // Resolves to App\Models\User
>>> show EloquentModel // Resolves to Illuminate\Database\Eloquent\Model
>>> ls Model // Lists members of Illuminate\Database\Eloquent\ModelCombine with warmAutoload and implicitUse configuration for the best experience!
The ls, doc, and show commands recognize magic methods and properties declared via @method and @property docblock tags. Magic members display in magenta to distinguish them from real methods and properties.
Inheritance works as expected: magic members from parent classes, interfaces, and traits are included, with child declarations taking precedence.
Tab completion also works with magic methods and properties.