is Short tag good practice in php?

前端 未结 4 518
长发绾君心
长发绾君心 2020-12-11 19:56

if I enable short tag = true, then I can use like below


Instead of



        
4条回答
  •  孤城傲影
    2020-12-11 21:00

    Short tags are considered to be a bad practice because they are not XML compliant... whether you care about that or not is another issue.

    Short echos are not a bad practice, it's just not the best. PHP is a templating engine, however much better engines are available (Twig, Mustache, Smarty, etc). Most frameworks include their own templating engine so short tags don't need to be used.

    Up to and including PHP 5.3, these types of tags were considered to be the same thing. Since PHP 5.4 however they've been separated out and short echo is allowed without enable-short-tags being turned on. Since PHP 5.3 is no longer supported, the only concern is if you're being forced to use an unsupported version, which obviously has it's own implications. :)

提交回复
热议问题