开发者

Coding convention [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

PHP coding conventions?

Are there any coding conventions regarding PHP? I'm looking for naming convention in particular 开发者_运维百科such as:

For function use nameOfFunction() rather than name_of_function()

or

For variables don't use $first_array = array() but $array['first'] = array()

or

Classes should always start with a capital letter: class Name

Are there any? Shouldn't they be defined so that different programmers will now how the entire code is written?


  1. nameOfFunction vs name_of_function - this one is entirely up to you. PHP itself doesn't even stick to a consistent scheme in this regard.

  2. Those two things are different, and can't really be compared, especially in the context of coding conventions.

  3. AFAIK, it's fairly common across quite a few programming languages that classes start with a capital letter (and hence, variables and functions don't).

Edit: Sorry, I just re-read the question and saw that you were looking for a more general document. The Zend Coding Standards are pretty good for that.


There are the PEAR Standards


Some standard like Zend Framework's : http://framework.zend.com/manual/en/coding-standard.html

Php_CodeSniffer allows to verify if your code is compatible with some standards and also custom standards.

http://pear.php.net/package/PHP_CodeSniffer/redirected


AFAIK there's no such thing as a document like Python PEPs for PHP code conventions.

Here you have some links from Google searches that try to address this:

http://svn.apache.org/repos/asf/shindig/trunk/php/docs/style-guide.html http://www.phpbuilder.com/columns/tim20010101.php3?page=2

There's this Style Guide frm CodeIgniter web framwrok project, it could work as a guideline in creating some personal or corporate conventions.

Hope this helps, regards.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜