auto_prepend_file在cli模式下不起作用 [英] auto_prepend_file is not working in cli mode

查看:58
本文介绍了auto_prepend_file在cli模式下不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Mac上运行auto_prepend_file:

I cannot get an auto_prepend_file run on my mac:

# cat /opt/local/lib/php/test.php
<?php
function test() { return 'foo'; }

# php --ini | grep php.ini
Configuration File (php.ini) Path: /opt/local/etc/php5
Loaded Configuration File:         /opt/local/etc/php5/php.ini

# cat /opt/local/etc/php5/php.ini | grep auto_prepend_file
auto_prepend_file = "/opt/local/lib/php/test.php"

# ls -la /opt/local/etc/php5/php.ini
-rw-r--r--   1 root  admin  68630 Jul 27 13:53 /opt/local/etc/php5/php.ini

# php -r "echo ini_get('auto_prepend_file');"
/opt/local/lib/php/test.php

但是然后...

# php -r "echo test();"
Fatal error: Call to undefined function test() in Command line code on line 1

# php -i | grep auto_prepend_file
auto_prepend_file => /opt/local/lib/php/test.php => /opt/local/lib/php/test.php

它通过(重新启动的)apache工作。

It works through the (restarted) apache.

您是否知道我可能做错了什么?

Do you have any idea what I could have made wrong?

推荐答案

<当直接通过 -r 命令行开关运行代码时,不会执行p> auto_prepend_file 。无论您是从CLI调用PHP本身还是在可执行文件的shebang中指定了PHP本身,当您在命令行上执行PHP文件时,它都能正常工作。

auto_prepend_file is not executed when you run code directly through the -r commandline switch. It works fine when you execute PHP files on the commandline, regardless if PHP itself is called from the CLI or it is specified in the shebang of the executable file.

这篇关于auto_prepend_file在cli模式下不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆