开发者

Drop into read-eval-print loop from PHP code?

开发者 https://www.devze.com 2022-12-30 19:01 出处:网络
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

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 cl开发者_如何转开发arify: 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.


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(); }
0

精彩评论

暂无评论...
验证码 换一张
取 消