Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP Standards Recomendations | PSR 1 & PSR 2

PHP Standards Recomendations | PSR 1 & PSR 2

Ngalam Backend Community

September 17, 2018
Tweet

More Decks by Ngalam Backend Community

Other Decks in Technology

Transcript

  1. PSR  PHP Standards Recommendations  Interoperability (Memudahkan kolaborasi antar

    project)  PSR-1 : standar penulisan kode PHP  PSR-2 : style guide kode PHP dan merupakan pengembangan dari PSR-1
  2. Kenapa PSR?  PHP sebelumnya tidak memiliki standar  PHP

    mulai masuk ke ranah perusahaan-perusahaan besar  Menjamurnya PHP framework  Standarisasi
  3. Sejarah Singkat PSR  Konferensi php|tek tahun 2009 : diskusi

    developer agar mereka bisa bekerja dalam project yang berbeda tersebut.  Pembentukan Framework Interoperability Group (FIG)  Beranggotakan seluruh developer yang mengembangkan aplikasi web berbasis PHP  Symfony, CakePHP, PyroCMS, phpDocumentor dan bahkan Composer.
  4. PSR-1: Basic Coding Standard Overview  use only <?php and

    <?= tags.  Class names MUST be declared in StudlyCaps Class FooBar{ };  Class constants MUST be declared in all upper case with underscore separators. const FOO_BAR;  Method names MUST be declared in camelCase. function fooBar(){}
  5. PSR-2: Coding Style Guide  Code MUST follow a “coding

    style guide” PSR [PSR-1].  Code MUST use 4 spaces for indenting, not tabs.  There MUST be one blank line after the namespace declaration  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.