PHP Training in Coimbatore|PHP training Coimbatore|PHP certification
5 Ways to Awesome-ize Your (PHP) Code
-
Upload
jeremy-kendall -
Category
Technology
-
view
2.536 -
download
1
description
Transcript of 5 Ways to Awesome-ize Your (PHP) Code
![Page 1: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/1.jpg)
5 Ways to Awesome-ize Your (PHP) Code
Jeremy Kendall
Thursday, November 7, 13
![Page 2: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/2.jpg)
Thursday, November 7, 13
![Page 3: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/3.jpg)
I love to code
Thursday, November 7, 13
![Page 4: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/4.jpg)
I love to code
I’m terribly forgetful
Thursday, November 7, 13
![Page 5: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/5.jpg)
I love to code
I’m terribly forgetful
I take pictures
Thursday, November 7, 13
![Page 6: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/6.jpg)
I love to code
I’m terribly forgetful
I take pictures
I work at OpenSky
Thursday, November 7, 13
![Page 7: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/7.jpg)
What Are These 5 Ways of Which You Speak?
Thursday, November 7, 13
![Page 8: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/8.jpg)
Use Version Control
Thursday, November 7, 13
![Page 9: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/9.jpg)
Use Version Control
‣ If you aren’t using version control, use git
Thursday, November 7, 13
![Page 10: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/10.jpg)
Use Version Control
‣ If you aren’t using version control, use git
Install git
Thursday, November 7, 13
![Page 11: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/11.jpg)
Use Version Control
‣ If you aren’t using version control, use git
Install git
cd /path/to/project
Thursday, November 7, 13
![Page 12: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/12.jpg)
Use Version Control
‣ If you aren’t using version control, use git
Install git
cd /path/to/project
git init
Thursday, November 7, 13
![Page 13: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/13.jpg)
Use Version Control
‣ If you aren’t using version control, use git
Install git
cd /path/to/project
git init
git add .
Thursday, November 7, 13
![Page 14: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/14.jpg)
Use Version Control
‣ If you aren’t using version control, use git
Install git
cd /path/to/project
git init
git add .
git commit -m “Just saved the company”
Thursday, November 7, 13
![Page 15: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/15.jpg)
Use Version Control
‣ If you aren’t using version control, use git
Install git
cd /path/to/project
git init
git add .
git commit -m “Just saved the company”
‣ Interactive tutorial at http://try.github.io
Thursday, November 7, 13
![Page 16: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/16.jpg)
or Else . . .
Thursday, November 7, 13
![Page 17: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/17.jpg)
Error Reporting: Turn it Up!
Thursday, November 7, 13
![Page 18: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/18.jpg)
Error Reporting: Turn it Up!‣ Turn error reporting all the way up in dev
Thursday, November 7, 13
![Page 19: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/19.jpg)
Error Reporting: Turn it Up!‣ Turn error reporting all the way up in dev
‣ Helps find existing problems
Thursday, November 7, 13
![Page 20: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/20.jpg)
Error Reporting: Turn it Up!‣ Turn error reporting all the way up in dev
‣ Helps find existing problems
‣ Helps head off future pain
Thursday, November 7, 13
![Page 21: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/21.jpg)
Error Reporting: Turn it Up!‣ Turn error reporting all the way up in dev
‣ Helps find existing problems
‣ Helps head off future pain
‣ Don’t say it’s just an E_NOTICE . . .
Thursday, November 7, 13
![Page 22: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/22.jpg)
Error Reporting: Turn it Up!‣ Turn error reporting all the way up in dev
‣ Helps find existing problems
‣ Helps head off future pain
‣ Don’t say it’s just an E_NOTICE . . .
Thursday, November 7, 13
![Page 23: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/23.jpg)
Error Reporting: Dev
display_errors = Ondisplay_startup_errors = Onerror_reporting = -1log_errors = On
Thursday, November 7, 13
![Page 24: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/24.jpg)
Error Reporting: Prod
display_errors = Offdisplay_startup_errors = Offerror_reporting = E_ALLlog_errors = On
Thursday, November 7, 13
![Page 25: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/25.jpg)
Ditch NIH
Thursday, November 7, 13
![Page 26: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/26.jpg)
Ditch NIH
‣ If you write it all yourself . . .
Thursday, November 7, 13
![Page 27: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/27.jpg)
Ditch NIH
‣ If you write it all yourself . . .
‣ . . . you maintain it all yourself
Thursday, November 7, 13
![Page 28: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/28.jpg)
Ditch NIH
‣ If you write it all yourself . . .
‣ . . . you maintain it all yourself
‣ Eventually you have very little time for either . . .
Thursday, November 7, 13
![Page 29: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/29.jpg)
Real, Actual Work
Thursday, November 7, 13
![Page 30: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/30.jpg)
Real, Actual Work
Thursday, November 7, 13
![Page 31: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/31.jpg)
A Life
Thursday, November 7, 13
![Page 32: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/32.jpg)
Ditch NIH
Thursday, November 7, 13
![Page 33: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/33.jpg)
Ditch NIH
‣ Offload work to the open source community
Thursday, November 7, 13
![Page 34: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/34.jpg)
Ditch NIH
‣ Offload work to the open source community
‣ Install Composer (http://getcomposer.org)
Thursday, November 7, 13
![Page 35: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/35.jpg)
Ditch NIH
‣ Offload work to the open source community
‣ Install Composer (http://getcomposer.org)
‣ Search Packagist (http://packagist.org)
Thursday, November 7, 13
![Page 36: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/36.jpg)
Ditch NIH
‣ Offload work to the open source community
‣ Install Composer (http://getcomposer.org)
‣ Search Packagist (http://packagist.org)
‣ Add dependency to composer.json
Thursday, November 7, 13
![Page 37: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/37.jpg)
Ditch NIH
‣ Offload work to the open source community
‣ Install Composer (http://getcomposer.org)
‣ Search Packagist (http://packagist.org)
‣ Add dependency to composer.json
‣ Run composer install or composer update
Thursday, November 7, 13
![Page 38: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/38.jpg)
Ditch NIH
‣ Offload work to the open source community
‣ Install Composer (http://getcomposer.org)
‣ Search Packagist (http://packagist.org)
‣ Add dependency to composer.json
‣ Run composer install or composer update
‣ Everyone needs logging. Go install monolog.
Thursday, November 7, 13
![Page 39: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/39.jpg)
DRY Up Your DB
Thursday, November 7, 13
![Page 40: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/40.jpg)
DRY Up Your DB
‣ If you’re not using PDO, switch now.
Thursday, November 7, 13
![Page 41: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/41.jpg)
DRY Up Your DB
‣ If you’re not using PDO, switch now.
‣ If you’re not using prepared statements, switch now.
Thursday, November 7, 13
![Page 42: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/42.jpg)
DRY Up Your DB
‣ If you’re not using PDO, switch now.
‣ If you’re not using prepared statements, switch now.
‣ Replace connections and queries one at a time
Thursday, November 7, 13
![Page 43: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/43.jpg)
DRY Up Your DB
‣ If you’re not using PDO, switch now.
‣ If you’re not using prepared statements, switch now.
‣ Replace connections and queries one at a time
‣ (or one group at a time)
Thursday, November 7, 13
![Page 44: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/44.jpg)
DRY Up Your DB
‣ If you’re not using PDO, switch now.
‣ If you’re not using prepared statements, switch now.
‣ Replace connections and queries one at a time
‣ (or one group at a time)
‣ Combine with simple data access objects
Thursday, November 7, 13
![Page 45: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/45.jpg)
DRY Up Your DBclass UserDao{ protected $db;
public function __construct(\PDO $db) { $this->db = $db; }
public function find($id) { $sql = 'SELECT * FROM users WHERE id = :id'; $stmt = $this->db->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute();
return $stmt->fetch(); }}
Thursday, November 7, 13
![Page 46: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/46.jpg)
DRY Up Your DBclass UserDao{ protected $db;
public function __construct(\PDO $db) { $this->db = $db; }
public function find($id) { $sql = 'SELECT * FROM users WHERE id = :id'; $stmt = $this->db->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute();
return $stmt->fetch(); }}
Thursday, November 7, 13
![Page 47: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/47.jpg)
DRY Up Your DBclass UserDao{ protected $db;
public function __construct(\PDO $db) { $this->db = $db; }
public function find($id) { $sql = 'SELECT * FROM users WHERE id = :id'; $stmt = $this->db->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute();
return $stmt->fetch(); }}
Thursday, November 7, 13
![Page 48: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/48.jpg)
DRY Up Your DBclass UserDao{ protected $db;
public function __construct(\PDO $db) { $this->db = $db; }
public function find($id) { $sql = 'SELECT * FROM users WHERE id = :id'; $stmt = $this->db->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute();
return $stmt->fetch(); }}
Thursday, November 7, 13
![Page 49: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/49.jpg)
DRY Up Your DBclass UserDao{ protected $db;
public function __construct(\PDO $db) { $this->db = $db; }
public function find($id) { $sql = 'SELECT * FROM users WHERE id = :id'; $stmt = $this->db->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute();
return $stmt->fetch(); }}
Thursday, November 7, 13
![Page 50: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/50.jpg)
Or Just Pick Something from Packagist
Thursday, November 7, 13
![Page 51: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/51.jpg)
Start Writing Beautiful Code
Thursday, November 7, 13
![Page 52: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/52.jpg)
Start Writing Beautiful Code‣ It’s time for a coding standard!
Thursday, November 7, 13
![Page 53: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/53.jpg)
Start Writing Beautiful Code‣ It’s time for a coding standard!
‣ Makes life so much easier
Thursday, November 7, 13
![Page 54: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/54.jpg)
Start Writing Beautiful Code‣ It’s time for a coding standard!
‣ Makes life so much easier
‣ Pick someone else’s
Thursday, November 7, 13
![Page 55: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/55.jpg)
Start Writing Beautiful Code‣ It’s time for a coding standard!
‣ Makes life so much easier
‣ Pick someone else’s
‣ Use automated tools to enforce
Thursday, November 7, 13
![Page 56: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/56.jpg)
Start Writing Beautiful Code‣ It’s time for a coding standard!
‣ Makes life so much easier
‣ Pick someone else’s
‣ Use automated tools to enforce
‣ php-cs-fixer
Thursday, November 7, 13
![Page 57: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/57.jpg)
Start Writing Beautiful Code‣ It’s time for a coding standard!
‣ Makes life so much easier
‣ Pick someone else’s
‣ Use automated tools to enforce
‣ php-cs-fixer
‣ PHP_CodeSniffer
Thursday, November 7, 13
![Page 58: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/58.jpg)
Start Writing Beautiful Code‣ It’s time for a coding standard!
‣ Makes life so much easier
‣ Pick someone else’s
‣ Use automated tools to enforce
‣ php-cs-fixer
‣ PHP_CodeSniffer
‣ Refactor bit-by-bit
Thursday, November 7, 13
![Page 59: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/59.jpg)
Bonus!
Thursday, November 7, 13
![Page 60: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/60.jpg)
PHP: The Right Way
Thursday, November 7, 13
![Page 61: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/61.jpg)
PHP: The Right Way
‣ Go to http://www.phptherightway.com/
Thursday, November 7, 13
![Page 62: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/62.jpg)
PHP: The Right Way
‣ Go to http://www.phptherightway.com/
‣ Start reading
Thursday, November 7, 13
![Page 63: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/63.jpg)
PHP: The Right Way
‣ Go to http://www.phptherightway.com/
‣ Start reading
‣ Don’t stop reading
Thursday, November 7, 13
![Page 64: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/64.jpg)
PHP: The Right Way
‣ Go to http://www.phptherightway.com/
‣ Start reading
‣ Don’t stop reading
‣ Do it “The Right Way” for 6 months
Thursday, November 7, 13
![Page 65: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/65.jpg)
PHP: The Right Way
‣ Go to http://www.phptherightway.com/
‣ Start reading
‣ Don’t stop reading
‣ Do it “The Right Way” for 6 months
‣ Then pick and choose
Thursday, November 7, 13
![Page 66: 5 Ways to Awesome-ize Your (PHP) Code](https://reader033.fdocuments.in/reader033/viewer/2022052619/555a07b8d8b42ad00a8b53d1/html5/thumbnails/66.jpg)
Thanks!
http://about.me/jeremykendall
@jeremykendall
http://365.jeremykendall.net
Thursday, November 7, 13