Which Coding convention to follow for PHP? [closed

2019-01-15 20:13发布

Should I stick with Sun's Java code conventions for PHP code?

9条回答
萌系小妹纸
2楼-- · 2019-01-15 20:34

If you are in a business follow the business code convention.

If it's for a personal project you can get the specific language specification (if you do Java than Java, if you do Php than PHP). If it's your personal project you can change few things if you desire...

If you do open source project, you should go see what's already in place.

查看更多
太酷不给撩
3楼-- · 2019-01-15 20:45

For PHP, i'd suggest to follow Zends suggestions

As you might know, Zend is the most widely used framework!

查看更多
SAY GOODBYE
4楼-- · 2019-01-15 20:46
甜甜的少女心
5楼-- · 2019-01-15 20:46

There are many different coding conventions out there. Have a look at what other people use (read some example code and see how easy it is to understand what is being done) and take your pick.

The important part is to choose one and stick to it.

查看更多
叛逆
6楼-- · 2019-01-15 20:48

There are pros and cons to any coding style. I spend a lot of time working with code from many sources doing integrations so sometimes end up seeing many different styles in a single day (different naming conventions, braces placement, tabs vs spaces etc)

As far as I'm concerned - the most important thing if you are working with existing code is to follow the style of the code that you are editing. If you don't you make things harder for anyone following after you.

If you are writing new code than you should have freedom to do it the way that makes you most efficient.

I find that company coding guidelines are often far to detailed and end up being forgotten after a few years and a bit of churn in the software team ;-)

查看更多
贼婆χ
7楼-- · 2019-01-15 20:55

As Gordon says, the Zend and PEAR standards are the effective industry standard.

However, the company's code quite possibly pre-dates these so depending on the size of the code base there may be little value in investing the time to make the move to one of these. (That said, if they ever want to use static code analysis tools you could possibly use this as an impetus to seriously consider moving to Zend, etc.)

However, being realistic, as long as they have a sensible standard that they stick to there's no real issue here - you'll find yourself adjusting how you "see" the code accordingly.

查看更多
登录 后发表回答