Using PsySH for Faster Moodle Development
Use PsySH to inspect Moodle state faster during development and debugging, without rewriting ad hoc test code for every question.
Summary: This guide shows how to use PsySH as a project-scoped REPL for Moodle development, with the correct PHP version and a bootstrap file kept outside the tracked repository.
This is a developer convenience workflow, but it becomes genuinely useful on complex Moodle projects because it lets you inspect application state interactively without littering the repository with one-off debug scripts.
Install PsySH per project, not globally by default
The SOP uses a project-local installation so each Moodle codebase can use the correct PHP version and dependency set. A typical install looks like:
php7.4 /usr/bin/composer require psy/psysh:^0.11
Use the PHP binary that matches the project, especially on older Moodle or Totara sites.
Create an init.php bootstrap outside the Git-tracked Moodle tree
The real value of the REPL is that it can bootstrap Moodle and expose objects such as $CFG, $DB, and application helpers. Keep that bootstrap file adjacent to the project but outside the tracked webroot so you do not accidentally commit local tooling.
Add a launcher script
Create a small wrapper such as moodlerepl that:
- uses the correct PHP binary
- loads the project bootstrap file
- starts PsySH in a predictable context
This turns the REPL from an experiment into a repeatable project tool.
Use it for inspection, not permanent fixes
The REPL is great for checking records, testing API calls, and validating assumptions quickly. It is not a substitute for real tests, versioned maintenance scripts, or proper development workflow.
Solin specializes in Moodle development workflows, debugging, and technical maintenance. Need help? Contact us.
Solin helps developers work faster in Moodle and Totara codebases with practical tooling, debugging workflows, and engineering support. Need help? Contact us.
Contact us