Which Coding convention to follow for PHP? [closed

2019-01-16 10:04发布

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

9条回答
相关推荐>>
2楼-- · 2019-01-16 11:00
Summer. ? 凉城
3楼-- · 2019-01-16 11:02

You should be following one of the PSR standards for PHP approved by the Framework Interop Group

  • PSR-0 - Aims to provide a standard file, class and namespace convention..
  • PSR-1 - Aims to ensure a high level of technical interoperability between shared PHP code.
  • PSR-2 - Provides a Coding Style Guide for projects looking to standardise their code.
  • PSR-3 - Describes a common interface for logging libraries; the LoggerInterface exposes eight methods to write logs to the eight RFC 5424 levels.
  • PSR-4 - Describes a specification for autoloading classes from file paths. It is fully interoperable, and can be used in addition to any other autoloading specification, including PSR-0.
查看更多
做个烂人
4楼-- · 2019-01-16 11:03

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.

查看更多
登录 后发表回答