Are there any howtos for using the PHP command line interactively?
I found a lot about running scripts 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.