PSR-2编码标准:为什么没有关闭PHP标签的文件只包含PHP? [英] PSR-2 coding standard: why no closing PHP tag in files containing only PHP?

查看:258
本文介绍了PSR-2编码标准:为什么没有关闭PHP标签的文件只包含PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在评论中只听到 PSR-2编码标准对此问题:是否有任何理由使用公共关键字before方法和成员变量名?

I just heard of the PSR-2 coding standard in a comment on this question: Is there any reason to use the "public" keyword before method and member variable names?

我对PSR-2标准中的一个规则有疑问:

I have a question on one of the rules in the PSR-2 standard:


关闭?>标记在仅包含PHP的文件中必须省略。

The closing ?> tag MUST be omitted from files containing only PHP.

这是什么意思?

推荐答案

在php脚本中不使用结束标记是一个很好的通用规则。注意,关闭标签之后的所有内容都会发送到客户端(浏览器),即使是白色字符,因此如果您使用结束标签和新行或任何其他白色字符,它将被发送到浏览器。在大多数情况下,这种行为是不可取的。

It is a good universal rule not using closing tag in php scripts. Note that everything after that closing tag is sent to client (browser) even white characters so if you're using closing tag and new line or any other white character it will be sent to browser. In most cases this behavior is not desirable.

这篇关于PSR-2编码标准:为什么没有关闭PHP标签的文件只包含PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆