logo

Quick PHP REPL

Laravel Tinker isn't the only game in town. It builds on some of these tools, actually.

Aaron Saray
Aaron Saray
2025-03-27

A REPL (Read-Eval-Print-Loop) is useful in a lot of cases. It allows you to run your code in this specific environment in a way that can be particularly useful with debugging.

So, what if you need a REPL in PHP but you don't have Laravel Tinker available (yet?).

First, PHP has this built in already. You can launch the PHP REPL on the command line like so:

php -a

Now, you'll be in a PHP environment. Remember, it is just a basic, PHP environment. A lot of the useful comforts you might expect are not available. This experience is a lot like a vanilla instance of a MySQL terminal connection.

Need a little bit more? You might try Psysh - which is a wrapper around the standard PHP REPL. It allows things like tab completion, documentation and the ability to launch itself directly in your application context - like a debug point.

And, if you're in Laravel, you can reach directly for Tinker.

Aaron

PS: On your way to Laravel, but need some help with your legacy PHP application? Turns out, I know a guy or two that can modernize PHP projects for you.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.