
Choosing the right language isn’t an easy thing to do, with countless programming languages, each with distinct advantages and disadvantages – and its not really possible to know all of them. I have been swearing by PHP as my web development language but lately I’ve been tempted to try out Ruby on Rails (although an article from ‘Stuart Herbert on PHP’ changed my mind) and Python (I use it for all my small scripts – but havn’t given mod_python / Django a chance yet) has some awesome advantages such as its clean syntax and class design, but more importantly, I have fallen in love with its interactive shell.
The interactive shell allows you to easily test code, and make sure everythings working as expected. Pythons introspection design also allows you to look into variables, check the documentation on functions from inside the program – and makes for an incredibly powerful code testing station. If you havn’t tried out Python yet, read Mark Pilgrims free online Dive Into Python book (its very well written, although it is intended for people who have coded in one of the major C-style languages before).
PHP has offered an interactive console which can be run by `php -a` from the command line, although php must be compiled with GNU readline or BSD’s libedit (all of our php web hosting servers will work). This shell is significantly less powerful then the Python one (mainly due to the lack of an introspection system like Python), requires semicolons (I suppose not the biggest issue, but annoying for single line statements) and also closes on any fatal error.
I’ve recently come across atleast a partial solution to those problems… ‘phpsh‘ – A PHP interactive shell (written mostly in Python) that Facebook has released open-source along with their recent Platform release. It no longer requires the semicolons, automatically restarts the php parser on the fatal errors, helps the lack of introspection with a built in documentation loader and also throws in tab-completion for good measure. While its still no Python interactive shell – its a lot more usable than than the normal `php -a`, and I can see myself leaving it open while developing future appications
josh@lusion.co.za:~/phpsh$ ./phpsh
php> print 'Hello world'
Hello world
php> for ($x=0;$x<10;$x++) print $x
0123456789
php> $v = array('cat'=>'hat','rat'=>'hole','mouse'=>'trap','josh'=>'lusion')
php> print_r($v)
Array
(
[cat] => hat
[rat] => hole
[mouse] => trap
[josh] => lusion
)php> ksort($v)
php> print_r($v)
Array
(
[cat] => hat
[josh] => lusion
[mouse] => trap
[rat] => hole
)php> print base64_decode('bHVzaW9uLmNvLnph')
lusion.co.zaphp> die('roar')
roarPHP died. Restarting: php -q /home/josh/phpsh/phpsh.php
php> while (!$succeed) $try++;



