How to use the php command line interactively?
Are there any howtos for using the php command line interactively? I found a lot about running sripts that are in text-files, but not really about the shell with the prompt where I type in commands: $ php -a Interactive shell php > echo "hello world"; hello world php > $a = 1; php > echo $a; 1 php > exit; $ When I go to the linux shell and run php -a I get the php shell. Can I load classes that live in files? What are the rules here?
The rules aren't any different to a normal PHP script - just think of it like reading from a very slow disk... The only real difference is that it can't read ahead, so you have to define functions before you use them. You can use include or require as normal to load classes.
Instructions to install phpsh in Ubuntu 10.04 Server edition. Get phpsh source and extract wget http://github.com/facebook/phpsh/zipball/master sudo apt-get install unzip mkdir temp mv facebook-phpsh-8438f3f.zip temp cd temp unzip facebook-phpsh-8438f3f.zip phpsh uses python, install dependencies sudo apt-get install python-setuptools sudo apt-get install linux-headers-$(uname -r) sudo apt-get install build-essential sudo apt-get install python-dev sudo apt-get install sqlite3 libsqlite3-dev sudo easy_install pysqlite sudo apt-get install libncurses5-dev sudo easy_install readline Setup phpsh, run and see that is works sudo python setup.py install phpsh $a = array("a"=>1,"b"=>2); print_r($a)
The interactive mode for php is somewhat limited. You may find phpsh more useful.
I believe you can use include. You can include files relative to the location you called the command.
There is another minor difference that could be problematic if you rely on the class-autoloading-behavior of PHP: Note: Autoloading is not available if using PHP in CLI interactive mode. Source: Using PHP from the command line and Autoloading Objects
Use Boris Python has one. Ruby has one. Clojure has one. Now PHP has one too. Boris is PHP's missing REPL (read-eval-print loop), allowing developers to experiment with PHP code in the terminal in an interactive manner. If you make a mistake, it doesn't matter, Boris will report the error and stand to attention for further input.
How to create mysql table in php using class(oops) in php?
codeigniter and DataMapper. The relationship table in different servers, how?
PHP: setlocale() does not work
PHP shell_exec 'wkhtmltopdf' returns null even though successful completion
change wordpress plugin source code; no change on the site
Display only the last 300 MYSQL Results with a PHP pagination system
Display modified date outside the loop
PHP does not store strings in $_SESSION
MongoDB - Aggregation Framework, PHP and averages
PHP if/else statement function problems
Linking out to URL directly from PHP search query
Foreach loop, and array building
Mysql WHERE NOT EXISTS (query) OR (query)
Select One Active Image from multiple Multiple Images
MySQL GROUP By and ORDER BY conflict
Syntax error in update trouble [closed]