Initialising PHP interactive
php
Solution
As Tomas Creemers mentioned, you have to use auto_prepend_file PHP flag to auto-require a file. For example:
<?php
# foo.php
function bar() { print "Bar.\n"; }
You can load the PHP interpreter like this:
php -d auto_prepend_file=$PWD/foo.php -a
Session:
Interactive shell
php > bar();
Bar.
Or you can include file manually:
php -a
Session:
Interactive shell
php > include 'foo.php';
php > bar();
Bar.
Problem
I often find PHP's interactive mode—`php -a`—very useful, but it would be far more useful if I could start it and have a few commands executed right away to initialize my environment. Things like run the autoloader, set up a few `use` shortcuts for namespaces, etc. Here's an example: ``` include "../../autoloader.php"; use App/Foo/Bar as Bar; ``` I thought maybe I could just add these lines to a text file `initialize.txt` and then start the interactive mode with `php -a < initialize.txt`, but that didn't work. How can I do this?