PHP short_open_tag

PHP開発でビューと処理を分けて開発するのはMVCモデルに代表されるように良くある話です。
フレームワークを使用する場合は良いのですが、スクラッチ開発の場合にはやはり気をつけて分離しておかないと、と思い知りました。
既存プログラムの改修をしていたのですが、その構成は

・メイン実行プログラム
・テンプレートとして読み込む(require()で)HTML

この、テンプレートとして読み込むHTMLのテキストボックスの値が

<input type="test" value="<?=$htmlspecialchars($value)?>" >

みたいに、変数の値を表示させていたのですが、ローカルで動かしてみたらテキストボックスの中に
"<?=$htmlspecialchars($value)?>"がそのまま表示されていました。

なぜかと色々調べた結果、php.iniの「short_open_tag」という属性の値がoffになっていた。

; This directive determines whether or not PHP will recognize code between
;  tags as PHP source which should be processed as such. It's been
; recommended for several years that you not use the short tag "short cut" and
; instead to use the full  tag combination. With the wide spread use
; of XML and use of these tags by other languages, the server can become easily
; confused and end up parsing the wrong code in the wrong context. But because
; this short cut has been a feature for such a long time, it's currently still
; supported for backwards compatibility, but we recommend you don't use them.
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag
short_open_tag = Off

デフォルト値はOnなので気付きにくいのですが、XAMPPは開発用だからなのかOffになっていました。
これをOnにすれば解決しました。

この設定の次に、以下のような設定があり

; Allow ASP-style  tags.
; http://php.net/asp-tags
asp_tags = Off

これはもしやASPとの互換性のためなのかな?と思ったのですが、
そもそもお決まりの定数名とかグローバル変数名とかが違うのでどの程度便利なのかな?と思いました。
というか、php→aspとかasp→phpとか言う移行ってやるものかな?

あとその次の次の設定も気になったので調べてみました

; Enforce year 2000 compliance (will cause problems with non-compliant browsers)
; http://php.net/y2k-compliance
y2k_compliance = On

2000年問題?と読めたので気になりましたが、
コア php.ini ディレクティブに関する説明

y2k_compliance boolean
2000年問題対応を強制します (2000年問題非対応のブラウザにおいて、 問題が発生する可能性があります)。

ぐらいなことしか調べられませんでした。まあもう過去の話だしいいか。


Leave a Reply