【问题标题】:Embedding php 'if' statements in HTML not executing correctly in PHP7在 HTML 中嵌入 php 'if' 语句在 PHP7 中无法正确执行
【发布时间】:2017-02-16 10:01:02
【问题描述】:

我有一个 PHP MVC 网站,在我看来有很多这样的代码:

<? if($this->unallocatedCount > 0 && Session::get("user_internal") == "1"): ?>
    something
<? endif; ?>

它在 PHP5 中运行良好,但是我在使用 PHP7 的 Linux 服务器上托管同一网站的副本,并且此代码未正确执行。它的作用是执行这个:&lt;? if($this-&gt;,然后简单地输出它的其余部分。

这是典型的 PHP7 行为还是我只需要更改服务器上的 PHP 设置?

【问题讨论】:

标签: php html php-7 ubuntu-16.04


【解决方案1】:

你应该替换short open tags

<?php if($this->unallocatedCount > 0 && Session::get("user_internal") == "1"): ?>
    something
<?php endif; ?>

【讨论】:

  • 为什么在这里投反对票?
  • 嗯.. 什么?我想,我想念smth
  • 之前有一个 DV,现在我的 +1 变成了 0 ;)
  • 是的,我已经看过了,并且为@Anant cauze 做了同样的事情,他同意他的回答。
  • @bub 我同意你和 Dmytrechko 的意见。
【解决方案2】:

在 PHP 7 中,默认情况下禁用短标签。你必须修复它

<?php if($this->unallocatedCount > 0 && Session::get("user_internal") == "1"): ?>
    something
<?php endif; ?>

或在您的 php.ini 中启用短标签。

short_open_tag=开启

然后重启服务器...

【讨论】:

    猜你喜欢
    • 2021-04-18
    • 2017-02-15
    • 1970-01-01
    • 2019-08-28
    • 2019-07-29
    • 2020-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多