PHP 7.2.14 "short_open_tag = On"被忽略

标签 php

在全新安装运行 PHP 7.2.14 的 Fedora 28 时,我遇到了一个奇怪的问题,即主 php.ini 中的 short_open_tag = On 被忽略了。我已验证只有主 php.ini (/etc/php.ini) 中只有一个标志实例。我尝试使用 php_value short_open_tag 1 在 .htaccess 中设置标志。每次更改后我都会重新启动 Apache。但是当我用 phpinfo() 验证时,标志总是设置为关闭。这个标志是否最终被弃用并且更改根本没有反射(reflect)在 PHP 更改日志中 (http://php.net/ChangeLog-7.php)?查看 PHP 源代码(我不是专家)并没有建议覆盖,所以我无法解释。任何见解将不胜感激。

最佳答案

我会首先注意到这个问题看起来像 this one 的重复.如果不是,这是我的最佳答案。

PHP 文档有一个 page在开始标签上写着:

PHP also allows for short open tag <? (which is discouraged since it is only available if enabled using the short_open_tag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option).

检查 phpinfo(),您可能会看到标题为 Configure Command 的部分,其中包含编译选项。查看那里是否有 --enable-short-tags 选项。如果没有,请听@phil 并查找标题为已解析的其他 .ini 文件 的部分,其中可能会列出已解析的其他 ini 文件。

如果您的搜索与您在原始帖子中建议的一样彻底,但您仍然无法获得短标签,则可能在 apache 配置文件中将其关闭,或者 short_open_tag 指令可能存在于超过一处。 PHP.ini 指令将覆盖可能已设置的任何先前值。

grep 搜索可能会有所帮助。在我的 PHP 信息输出中,我看到了这些值:

Loaded Configuration File - /etc/php5/apache2/php.ini

Scan this dir for additional .ini files - /etc/php5/apache2/conf.d

我可以使用这个 grep 命令轻松搜索该位置的所有文件:

grep -ir 'short_open_tag'/etc/php5/apache2

如果您双重/三次检查所有这些 ini 文件并重新启动 apache,但仍然无法使 short_open_tag 设置起作用,则此值可能被设置为 apache 选项。我建议在 apache 配置文件中搜索对 short_open_tag 的任何引用。确切的目录位置在你的机器上可能不同,但这个 grep 命令对我有用

grep -ir 'short_open_tag'/etc/apache2

您还应该记住,您的 apache 配置可能没有设置为甚至打扰 .htaccess 文件,因此您尝试使用 .htaccess 覆盖可能是徒劳的,除非您将 apache 配置为实际使用 .htaccess 文件。假设您的 apache 配置确实需要解析您的 htaccess 文件,这似乎包含在 another question 中。在这里。

最后,如果您的服务器配置为使用 PHP-FPM,那么它会使用 PHP 进程池来处理来自 Web 服务器的 PHP 请求。如果是这种情况,您需要使用以下命令重新启动 php-fpm:

sudo service php7.0-fpm restart

注意:此命令在不同的机器上可能会有所不同。

关于PHP 7.2.14 "short_open_tag = On"被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54432754/

相关文章:

php - 当我向其中添加 LIMIT 关键字时,SQL 不工作

php - 运行结果集时的效率

javascript - 未捕获的类型错误 : scrollIntoView is not a function

php - 是否有 require_once 的 HTML 变体?

php - 数据库中所有用户的减量字段

php - 使用PHP和MySQLi对之前和之后的WHERE子句日期进行数据排序

javascript - 使用AJAX形式更新数据库

php - 从两个表中选择并计算查询

javascript - AJAX 响应文本不匹配

php - 多列动态 PHP 列表