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.
Database path on raspberry
When it comes to handle errors, in what sense, using Exceptions are better that utilize if…else…switch… etc.?
TCP/IP protocall, Android, PHP sending to and reciving from server
Dompdf error “No block-level parent found. Not good.”
php executing external process leaves script hanging
sql - mysql not able to get desired result for group_concat, group by, transpose
An AJAX HTTP error occurred.HTTP Result Code: 200Debugging information follows
redirect all traffic to https://www. on nginx
Files aren't getting uploaded
How to generate PHP tree view from array
Php App Engine Strtotime Error
Can't connect to MySQL server on 'localhost' (10061) (2003) error phpmyadmin using MAMP on windows 10
Mysqli update data if data exactly match with database
Why does Symfony2 logs file specify a different time than the server time?
Link id's between two mysql tables [closed]
Is there anything to help me create a sortable table (with search filters)?