-
Notifications
You must be signed in to change notification settings - Fork 318
Code reloading
PsySH can automatically reload modified files during your session. When you edit a file externally and return to PsySH, changes are picked up without restarting.
Code reloading requires one of these extensions:
| PHP Version | Extension |
|---|---|
| 8.0+ | uopz 5.0+ |
| 7.4 and earlier | runkit or runkit7 |
When supported, reloading is enabled automatically; no configuration needed.
Note
The details below apply to the uopz reloader (PHP 8.0+). The runkit reloader uses file reimporting via runkit_import(), which has different behavior and limitations. See the runkit documentation for details.
Each time you enter input, PsySH checks timestamps of included files. Modified files are parsed and reloaded using uopz functions to update definitions in place.
- β Method bodies (including private/protected)
- β Function implementations (and new functions!)
- β Class constants
- β Global constants
- β New class methods
- β Class properties (adding/removing)
- β Class inheritance or interfaces
- β Method signatures (parameter types/counts)
For structural changes, you'll need to restart PsySH.
By default, PsySH skips reloading "risky" code patterns:
-
Conditional definitions β Functions or constants defined inside
if,while,for, etc. These may not match the conditions that existed when the file was first loaded. - Static variables β Will reset to their initial values on reload (a warning is shown).
- Top-level side effects β Expressions, echo statements, etc. are not re-executed.
When code is skipped, you'll see a warning:
>>> my_helper()
Warning: Skipped conditional: if (...) { function my_helper() ... }
Use yolo to bypass safety checks and force-reload skipped code:
>>> yolo my_helper()
YOLO: Force-reloading ~/src/helpers.php
=> "result"
The !! shortcut repeats your last command:
>>> my_helper()
Warning: Skipped conditional: if (...) { function my_helper() ... }
>>> yolo !!
=> "result"
Warning
Force-reloading conditional code may cause unexpected behavior if runtime conditions have changed since the file was first loaded.
- Edit and test β Keep your editor and PsySH side by side for a tight feedback loop
- Watch for warnings β They indicate code that couldn't be fully reloaded
- Restart for big changes β Structural changes (new properties, inheritance) require a restart