Run interactive PHP code in a standalone REPL shell
GitHub RepoImpressions1.3k

Run interactive PHP code in a standalone REPL shell

@githubprojectsPost Author

Project Description

View on GitHub

PsySH: A REPL for PHP That Feels Like Home

If you've ever worked in Python or Node.js, you've probably enjoyed the instant feedback loop of a REPL (Read-Eval-Print Loop). You type a line of code, hit enter, and immediately see the result. For a long time, PHP developers watched from the sidelines—our workflow was save, refresh, debug. That changes with PsySH.

PsySH is a runtime developer console, interactive debugger, and REPL for PHP. It's not just a simple eval() shell; it's a full-featured environment that understands your codebase, lets you inspect and interact with running applications, and makes exploratory programming and debugging in PHP not just possible, but pleasant.

What It Does

In short, PsySH gives you a standalone interactive shell for PHP. You launch it from your terminal, and you're dropped into a prompt where you can write PHP code, define variables, call functions, instantiate classes, and see the output instantly. It's like having a conversation with your PHP interpreter.

But it goes beyond the basics. It can integrate with your existing project, providing context-aware autocompletion, inline documentation (doc command), and even a visual representation of complex data structures. You can also use it as a powerful interactive debugger by dropping a single line into your web application code.

Why It's Cool

The magic of PsySH is in its thoughtful design. It doesn't just execute code; it makes the process of exploring and debugging intuitive.

  • It's Context-Aware: When run inside a project, it can autocomplete your class names, method names, and constants. Type $this-> and hit tab—it knows what's available.
  • Built-in Help and Documentation: Forget a function signature? Use the doc json_encode command right in the shell to pull up the official PHP documentation.
  • Supercharged Output: Dumping an array or object gives you a clean, colorized, and readable tree structure, not the mess of print_r().
  • Debugger Superpowers: Add one line—eval(\Psy\sh());—into your app (like in an error handler or a specific route). When that code is hit, your terminal running PsySH becomes a live debugger for that request, letting you inspect the entire application state.
  • It's a Time Machine: The shell keeps a history of all your inputs and outputs. You can review, replay, and even save sessions.

How to Try It

Getting started is straightforward. The easiest way is to install it globally via Composer:

composer global require psy/psysh

Then, just run:

psysh

Boom. You're in. Start typing PHP.

> $greeting = "Hello, PsySH";
> echo $greeting;
Hello, PsySH
> $colors = ['red', 'green', 'blue'];
> var_dump($colors);
=> [
     "red",
     "green",
     "blue",
   ]

To use it as a debugger in your project, install it as a local dependency (composer require --dev psy/psysh) and then drop the eval(\Psy\sh()); line where you want your breakpoint. The project's README has excellent, detailed examples.

Final Thoughts

PsySH fundamentally improves the PHP development experience. It turns passive debugging (var_dump, die) into an active exploration. I find myself using it for quick calculations, testing a tricky regex, prototyping a small piece of logic before I write it into a file, or understanding a third-party library by interactively calling its methods.

It's one of those tools that, once you start using it, you wonder how you ever worked without it. It brings PHP's development workflow up to par with other modern languages, and it does it with style and solid engineering.


Follow us for more cool projects: @githubprojects

Back to Projects
Project ID: a140c986-9884-4d7f-b010-3a28585f0091Last updated: December 15, 2025 at 05:51 AM