Quick PHP REPL
This post is more than 18 months old. Technology changes quickly, so some of this content may be out of date (but that's not always the case). Please verify any technical or programming information against the current release.
Originally published on Mastering Laravel.
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 -aNow, 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.