Categorized | News

Interactive PHP

Posted on 06 June 2004 by Demian Turner

One of those aha moments, wish someone had pointed this out ages ago, thanks to Jon from for shedding the light.

After playing with Python recently I thought one of the most useful things was its interactive shell, where you could type in and evaluate variable expressions at the commandline.  “Why doesn’t PHP have this,” I lamented, having played with php -r at the command line and finding it pretty useless.  Up until now there’s been my ‘test’ folder which currently has 258 files in it.

“It does” retorted Jon, “what you need is php -a”.  And lo and behold he was right, but this little insight doesn’t seem to be mentioned anywhere save one of the comments on the relevant page.  If you’ve ever done a php –help to list the commandline options, the php -a found there doesn’t tell you very much.

So, all you need to do is issue a php -a at the command line (the php cli executable is generally in your path on unix systems and quite easy to add on windows), enter PHP mode by typing a <?php, enter the PHP expressions you want to evaluate, and prompt execution by hitting <ctrl-d> on unix or <ctrl-z> on windows.

Bookmark and Share

1 Comments For This Post

  1. demian Says:

    this has mysteriously stopped working in php 4.3.8 on windows 🙁

Leave a Reply



Demian Turner's currently-reading book recommendations, reviews, favorite quotes, book clubs, book trivia, book lists



PHPkitchen recommends you also check out the following sites :

Accounting for Small Businesses

FreeAgent sign-up