gpt4 book ai didi

php - 初始化 PHP 交互

转载 作者:可可西里 更新时间:2023-11-01 12:34:58 24 4
gpt4 key购买 nike

我经常发现PHP的交互模式--php -a -- 非常有用,但如果我可以启动它并立即执行一些命令来初始化我的环境,它会更有用。诸如运行自动加载器之类的事情,设置一些 use命名空间等的快捷方式。

这是一个例子:

include "../../autoloader.php";
use App/Foo/Bar as Bar;

我想也许我可以将这些行添加到文本文件中 initialize.txt然后使用 php -a < initialize.txt 启动交互模式但这没有用。

有人知道怎么做吗?

最佳答案

正如 Tomas Creemers 提到的,您必须使用 auto_prepend_file自动要求文件的 PHP 标志。例如:

<?php
# foo.php
function bar() { print "Bar.\n"; }

您可以像这样加载 PHP 解释器:

[hron@merlin tmp ] $ php -d auto_prepend_file=$PWD/foo.php -a
Interactive shell

php > bar();
Bar.
php >

或者您可以手动包含文件:

[hron@merlin tmp ] $ php -a
Interactive shell

php > include 'foo.php';
php > bar();
Bar.
php >

关于php - 初始化 PHP 交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18294683/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com