Skip to content

Code reloading

Justin Hileman edited this page Dec 15, 2025 · 2 revisions

πŸ”„ 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.

Requirements

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.

How it works

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.

What gets reloaded

  • βœ… Method bodies (including private/protected)
  • βœ… Function implementations (and new functions!)
  • βœ… Class constants
  • βœ… Global constants

What cannot be reloaded

  • ❌ 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.

Safety checks

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() ... }

The yolo command

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.

Tips

  • 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

Clone this wiki locally