PHP编码标准 [英] PHP coding standards

查看:62
本文介绍了PHP编码标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一些关于如何布局PHP代码的指导。我发现了一些很好的参考,例如:

I've been looking for some guidelines on how to layout PHP code. I've found some good references, such as the following:

http://www.dagbladet.no/development/phpcodingstandard/

这个问题上。

然而,没有一个得到我特别想知道的,这是HTML和PHP的集成。例如:

However, none of that quite gets to what I'm specifically wondering about, which is the integration of HTML and PHP. For example:


  1. 是否可以有一个以HTML标签开始的PHP文件,并且只在需要的地方插入PHP?或者你应该只有一个php部分包含所有的东西?

  2. 如果你有一大块PHP代码,在其中间是一组echo,只输出一个固定的HTML ,是更好地打破PHP,只是把HTML直接?

  3. 应该将函数全部定义在专用的php文件中,还是可以在文件顶部定义一堆函数并稍后在同一个文件中调用它们?

我可能还有其他问题要问,但我真的想找个人来指点某种在线资源

There's probably other questions I'd like to ask, but really I'm looking for someone to point me at some kind of resource online that offers guidance on the general idea of how HTML and PHP should be combined together.

推荐答案

这些方法没有一个共同的标准。东西。大多数语言在这个意义上比PHP更具限制性。

There's really not a single, common standard for these things. Most languages are more restrictive than PHP in this sense.

在后来的几年里,出现了许多所谓的框架,除了别的以外,他们定义了一组从命名,在哪里放置文件以及代码应该遵循的样式的一切规则。有几个框架,所以你不能真正选择一个,称之为标准。然而,大多数框架都有一个共性的子集。例如,大多数都遵循 PEAR编码标准的一些变体。

In the later years, a lot of so-called frameworks have emerged, and amongst other things they define a set of rules for everything from naming over where to place files and to which style your code should follow. There are several frameworks around, so you can't really pick one and call it the standard. However, most frameworks have a subset of commonality. For example, most follows some variant of the PEAR Coding Standards.

这篇关于PHP编码标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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