tags:

views:

49

answers:

1

Is there a way to drop into a read-eval-print loop from inside PHP code during execution, in a script that was run from the command line? That is, like php -a or phpsh? Or do I have to re-implement a REPL from scratch? I can't find any way to do it.

To clarify: the reason why I need to do this is that I want to automatically include all the files in my project once the REPL starts, instead of having to manually include everything by hand.

+1  A: 

Just load the file when you enter the php shell...

php -a

<?php require("core.php"); ?>

core.php:

 require_once("somefile.php");
 require_once("anotherfile.php");
 require_once("yetanotherfile.php");
 dosomething();
 // Here, it'll drop back to the shell.

If you have a core file that processes a request by calling a function, you can bypass that function call when it is remotely required, using:

if (basename($argv[0]) == basename(__FILE__)) { process_request(); }
CodeJoust
Is there a way to run a shell script that echos the require("core.php") line into the shell and then gives control back to the user? I tried doing this but it closes after the echo.
Michael Louis Thaler