对对象实例使用 $CamelCase,对其他所有内容使用 $lower_case
这是命名变量的简单约定:
对对象实例使用 $CamelCase 和“$lower_case”代表其他一切。
你能想出一个不使用它的理由吗?
几个月前我想出了这个约定,从那时起我就一直在一些小项目中使用它。我即将开始在一个大项目中使用它,所以我想确保我没有遗漏任何东西。
Here's a simple convention for naming variables:
Use $CamelCase for object instances
and "$lower_case" for everything else.
Can you think of a reason not to use it?
I came up with this convention a few months ago and I've been using it in a few small projects since then. I'm about to start using it in a big project so I want to be sure I'm not missing something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用最适合您的任何命名约定,只要该项目只能由您开发即可。
我们制定标准的原因是,当开发人员在一个项目上协作时,已经习惯了语法和命名约定,即我们所说的标准。
由于您在 PHP 中进行了专门的编码,因此我建议您使用众所周知的命名约定,例如 Zend 或 PEAR。
没有理由提出新的命名约定,除非所有程序员或处理代码的人员都选择这样做并经过适当的考虑。
一些约定:
我个人更喜欢 Zend 而不是 PEAR,但就标准而言,上述是最受欢迎的。
编辑:我使用的约定的一些示例。
$MY_GLOBAL_VARIABLE
$lowerUpper
Upper_For_Each_Segment
$this->lowerUpper
$this->_lowerUpper
ALL_UPPER_CASE
您可以稍微修改约定以满足您的要求,但最好坚持当时最流行的约定。
Use whatever naming convention that suites you best, as long as the project will only ever be developed on by you.
The reason we have standards is that when developers collaborate together on a project, there already used to the syntax and the naming conventions as the what we call the standard.
As your specifically coding in PHP then i would advise you to use a well known naming convention such as Zend or PEAR.
There is no reason what so ever to come up with a new naming convention unless all your programmers or people that work on the code all opt in for this and its thought out properly.
Some Conventions:
I Personally prefer Zend over PEAR but the above to are the most popular when it comes down to standards.
Edit: Some examples of the conventions i use.
$MY_GLOBAL_VARIABLE
$lowerUpper
Upper_For_Each_Segment
$this->lowerUpper
$this->_lowerUpper
ALL_UPPER_CASE
You can modify the convention slightly to fit your requirements but its best to stick to the most popular convention at the time.
通常遵循这一古老的三重规则:
$ALL_CAPS
表示名义常量。$Each_Word_Capped
作为全局变量。$no_words_capped
作为局部变量。请注意,使用此方案,您总是用下划线分隔单词:下划线充当空格字符来引导眼睛。这比你意识到的更有价值。这是一个完全一致的规则,并且比大多数替代规则更具可读性。尝试删除这篇文章中的空格,看看我的意思。
Usually one follows this age-old rules triple:
$ALL_CAPS
for nominal constants.$Each_Word_Capped
for global variables.$no_words_capped
for local variables.Notice how with this scheme, you always separate words with underscores: underscores serves as space characters to guide the eye. This is more valuable than you realize. This is a perfectly consistent rule, and much more readable than most alternatives. Try remove the spaces in this posting to see what I mean.