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

Matainable PHP Source Code

Matainable PHP Source Code

How to write matainable PHP Source Code

Bo-Yi Wu

July 25, 2012
Tweet

More Decks by Bo-Yi Wu

Other Decks in Technology

Transcript

  1. if ($arg === true) { //do something here } elseif

    ($arg === null) { //do something else here } else { //catch all do something here }
  2. if (($a == $b) and ($b == $c) or ($a

    == $e) ) { $a = $d; }
  3. if($arg === true) { //do something here } elseif($arg ===

    null) { //do something else here } else { //catch all do something here } 條件式 if 括號旁邊請留一個空白
  4. <?php while ($expr) { // structure body } <?php do

    { // structure body; } while ($expr);
  5. switch ($var) { case 0: echo 'First case, with a

    break'; break; case 1: echo 'Second case, which falls through'; // no break case 2: case 3: echo 'Third case, return instead of break'; return; default: echo 'Default case'; break; }
  6. if ($var == false and $other_var != 'some_value') if ($var

    === false or my_function() !== false) if ( ! $var)
  7. /** * Documentation Block Here */ class Session { //

    all contents of class // must be indented four spaces public function test() {} }
  8. /** * Documentation Block Here */ class Session { /**

    * Documentation Block Here */ public function get_flash($name, $data) { $closure = function($a, $b) { // Your closure code here } } }
  9. /** * Documentation Block Here */ class Session { var

    $test = null; /** * Documentation Block Here */ function get_flash($name, $data) { // Your code here } } 請勿使用 var 定義變數
  10. $sql = "SELECT `id`, `name` FROM `people` " . "WHERE

    `name` = 'Susan' " . "ORDER BY `name` ASC ";
  11.  PHP Framework Interop Group  PSR­0  PSR­1 

    PSR­2  Zend Framework Coding Standard for PHP 參考資料