LoginSignup
0
0

More than 3 years have passed since last update.

phpのshort_open_tagがOffの場合のエラー内容が分かりづらかった

Posted at

phpでviewをテンプレートエンジンとして実装している際に以下のような記載をしたところ
以下のようにエラーになりました。

<?php if ($is_ok): ?>
<p><?php echo $message1; ?></p>
<?php else: ?>
<p><?php echo $message2; ?></p>
<? endif; ?>
エラー内容
Fatal Error - Method Fuel\Core\View::__toString() must not throw an exception, caught ParseError: syntax error, unexpected end of file in /XXX/XXX.php on line 0

調べてみると、
<? endif; ?>
この部分が誤字脱字でした。
short_open_tagの指定が必要でした。

short_open_tagとは?

php.iniでshort_open_tagをONにすると<?php<?として省略できます。
が、このphp指定が抜けていたのでおかしくなったようです。

エラー内容が分かりづらい。。

ちなみにphp7.3でもデフォルト値はOnとコメント記載があったのに
設定自体はOffになっていました。

デフォルト設定
; short_open_tag
;   Default Value: On
;   Development Value: Off
;   Production Value: Off

php7.4からは<?はDeprecatedとなりphp8からは廃止される予定のようなので変わったのかな?

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0