PHPカンファレンス2013 今ドキのPHPの書き方 ~PHP逆引きレシピ改訂版~

48
今ドキのPHPの書き方 PHP逆引きレシピ改訂版~ PHP逆引きレシピ 改訂版 執筆チーム 浅野 (@ts_asano) 櫻井 雄大(@Y_Sakurai)

description

PHPカンファレンス2013で発表したスライドです。 PHP逆引きレシピ改訂版の改訂ポイントなどを紹介しています。

Transcript of PHPカンファレンス2013 今ドキのPHPの書き方 ~PHP逆引きレシピ改訂版~

  • 1. PHP PHP PHP (@ts_asano) (@Y_Sakurai)

2. 1 PHP 3. 2 4. 3 5. 4 PHP 2009629 6. 5 2009629 7. 6 4 PHP 5.35.45.5 PEARComposer ... 8. 7 2009PHP PHP PHP ... () 9. 8 HTML5 .../ 10. 9 11. 10 150 (40) 12. 11 Y^Y^Y^Y^Y^Y 13. 12 ... ... PHP PHP New! PHP 14. 13 Web PHP New! PHP45.2 PHP 15. 14 non-flatPHP 1 () 16. 15 New! New! 1 2 PHP 3 PHP 4 5 PEARSmarty 6 Web 7 8 9 10 1 2 PHP 3 PHP 4 5 6 7 Web 8 9 10 11 17. 16 (1) :/ (XAMPP) (Ver) (SPL) (Composer,,Smarty3) 18. 17 / XAMPP 1.8.3/MAMP 2.1.4 OpenSSL ... NetBeans git/hg/svnVCS PHPUnit, ... 19. 18 Nowdoc break,continue,isset() break, continue PHP5.35.5 20. 19 ... $str = 'string'; var_dump(isset($str['a'])); PHP5.35.4 21. 19 ... $str = 'string'; var_dump(isset($str['a'])); PHP5.35.4 PHP5.3: true PHP5.4: false 22. 20 (1) SPL 23. 21 (2) 5222 FuelPHP FuelPHP 24. 22 Composer ("") composer.json MVC 25. 23 composer.lock installcomposer.lock install... composer.lock VCS 26. 24 (2) (PDOSQLite) (PHPUnitSelenium) (XSS) (Xdebug) 27. 25 (1) MySQLSQLite PostgreSQL SQLite SQLitePHP 28. 26 (2) PDO+ (OFF) http://d.hatena.ne.jp/ockeghem/20090711/p1 PHP4 PHP4 MySQL-API() 29. 27 (3) PDO bindValue() bindParam() 3PDO::PARAM_*) 30. 28 bindParam()(1) On $intValue = 256; $prepare->bindParam(':id', $intValue, PDO:: PARAM_INT) var_dump($intValue); $prepare->execute(); var_dump($intValue); => int(3) 256 string(3) "256" 31. 29 bindParam()(2) bindParam()2 PARAM_INT $intValue bindValue() 32. 30 PDO::PARAM_*(1) $prepare = $db->prepare('SELECT * FROM t WHERE id = :id); $strValue = '123'; $prepare->bindValue(':id', $strValue, PDO::PARAM_INT); $prepare->execute(); => 'SELECT * FROM t WHERE id = '123'; (pdo_mysql) 33. 31 PDO::PARAM_*(2) PHP... (php/php-src master ext/pdo/pdo_stmt.c:320) PARAM_STR PARAM_INTbooleanint () PARAM_BOOLintbool PDO::PARAM_INT () 34. 32 PHPUnit PHP5.3: true PHP5.4: false 35. 33 (1) 36. 34 (2) () (CRAP) PHPUnitXdebug $ phpunit --coverage-html output_dir UnitTest.php 37. 35 (3) CRAP Change Risk Anti-Patterns (NG) 30 38. 36 PHPUnit_Selenium2(1) SeleniumPHP HTML 39. 37 PHPUnit_Selenium2(2) public function testForm() { $this->url('example.php'); $textbox = $this->byCssSelector('input[type="text"]'); $textbox->value('PHP'); $submit = $this->byCssSelector('input[type="submit"]'); $submit->click(); $element = $this->byCssSelector('body > div > p'); $this->assertEquals('PHP', $element- >text()); } 40. 38 PHPUnit_Selenium2(3) Selenium XAMPPMAMP Linux CORESERVER Selenium 41. 39 (1) 42. 40 (2) XSS ... ... ... (h()htmlspecialchars()) JavaScript 43. 41 (3) $u16 = mb_convert_encoding($matches[0], 'UTF-16'); $safe_str = preg_replace('/[0-9a-f]{4}/', 'u$0', bin2hex($u16)); Unicode ("uXXXX") 44. 42 (1) var_dump( '11111111111111111111' == '11111111111111111112' ); PHP5.4.3: true PHP5.4.4: false 45. 43 (2) PHP5.5 password_hash() PHP PHP5.3.7 46. 44 ... HTML5 47. 45 ... 48. 46 PHP 10