PHP Command Shell
Last week I wrote an interactive, command line PHP interpreter, and I've decided to post the source code here.
It's version 0.1, and it comes with a boatload of caveats: it only works under UNIX, and for that matter, only on UNIX systems that have a PHP interpreter installed in someplace like /usr/local/bin, which means that you either downloaded or installed with the CGI option. It doesn't support niceties like line continuation or command history convenience keys. Most of all, it's pretty simple. You could have probably written this in half an hour if you'd thought of it.
But it does do its basic job: processing each line you type in as PHP code. Variables that are set get remembered. If you want the shell to return the value of an expression, just don't end it with a semicolon or brace, and it'll give it back to you. You can always use echo if you want, too.
When you invoke it, you also have the option of giving it arguments that represent the names of one or more php files to be included prior to starting interaction. This gives you essentially the ability to run test bed scripts and then check values or code interactions to see if you're getting the behavior you'd expect.
I'll be writing a more complete FAQ for it before Too Long (TM). Please drop me a line if you're interested in this, especially if you'd like to help add missing features.
Comments