If you know python, maybe you know the interactive python shell, too. If you don’t know both, well, let me explain it. Python has it’s built in interactive shell. When you install python and you execute the command,
python, you will be introduced to a shell like interface where you could type python statements and have it evaluated and shown the result, right away. This is really convenience for learning purpose, or some simple snippet testing.
PHP does have this feature. If you try to lauch the php-cli with -a option (
php -a), you’ll landed on php’s interactive shell. However, it does not catch php error like python does. It will exit the shell when error encountered. This kind of behaviour limit the interactive ability. Imagine this, you’ve typed several line of codes you read on some tutorial site, however, right at the end of the line, you miss type some code and it raised error. This will force you to write all the script back from the first line. PHP does have another feature for snippet testing (beside writing to file and execute it). By using -r option, you can type the code all in one line and run it using this command:
php -r "some php code". But, this one have it’s own drawback. You will have to escape every quote you have, because it will be parsed by the main shell, before parsed by php.
phpsh is an interactive shell for php that features readline history, tab completion, quick access to documentation. It was developed at Facebook and ironically, is written mostly in python. It is open source and released under a modified BSD license.
It also able to catch error. Therefore, if you encounter it, you will be able to fix the code and run it again, interactively. Cool isn’t it!