Search code examples
phpzend-frameworkcoding-stylestandards

Latest coding standards/style in php


I already searched for the latest coding style/standards but most of the links are an year or two old and referring to this link Zend Coding Style. However the link is for version 1.12. My only point is this, now a days most of the people are declaring the functions in this style --

public function myfun ( ) {
....
....
}

and on Zend tutorial its something like this -

public function myfun()
{
    // all contents of function
    // must be indented four spaces
}

I am aware that this wont affect the functionality and its depend person to person, its just about following the best/latest practices, let me know if thr is any relevant link regarding this for following the best practices in coding style in php .


Solution

  • There is a standard developing by an initiative called the PHP Framework Interoperability Group (php-fig). This has members from some very prominent projects who are supporting the standard, some of these include:-

    • Zend Framework
    • Symfony
    • CakePHP
    • Amazon Web Services SDK
    • Drupal
    • Doctrine
    • PEAR

    PRS-2 has already been agreed on and covers basic coding style. It states for function declarations and class declarations:-

    Opening braces for classes MUST go on the next line, and closing braces MUST go on the next line after the body.

    Opening braces for methods MUST go on the next line, and closing braces MUST go on the next line after the body.