SlideShare a Scribd company logo
5 Ways to Awesome-ize
Your (PHP) Code

Jeremy Kendall

Thursday, November 7, 13
Thursday, November 7, 13
I love to code

Thursday, November 7, 13
I love to code
I’m terribly forgetful

Thursday, November 7, 13
I love to code
I’m terribly forgetful
I take pictures

Thursday, November 7, 13
I love to code
I’m terribly forgetful
I take pictures
I work at OpenSky

Thursday, November 7, 13
What Are These 5 Ways of
Which You Speak?

Thursday, November 7, 13
Use Version Control

Thursday, November 7, 13
Use Version Control
‣

Thursday, November 7, 13

If you aren’t using version control, use git
Use Version Control
‣

If you aren’t using version control, use git
Install git

Thursday, November 7, 13
Use Version Control
‣

If you aren’t using version control, use git
Install git
cd /path/to/project

Thursday, November 7, 13
Use Version Control
‣

If you aren’t using version control, use git
Install git
cd /path/to/project
git init

Thursday, November 7, 13
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
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
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

Interactive tutorial at http://try.github.io
or Else . . .

Thursday, November 7, 13
Error Reporting: Turn it Up!

Thursday, November 7, 13
Error Reporting: Turn it Up!
‣

Thursday, November 7, 13

Turn error reporting all the way up in dev
Error Reporting: Turn it Up!
‣
Helps find existing problems
‣

Turn error reporting all the way up in dev

Thursday, November 7, 13
Error Reporting: Turn it Up!
‣
Helps find existing problems
‣
Helps head off future pain
‣

Turn error reporting all the way up in dev

Thursday, November 7, 13
Error Reporting: Turn it Up!
‣
Helps find existing problems
‣
Helps head off future pain
‣
Don’t say it’s just an E_NOTICE . . .
‣

Turn error reporting all the way up in dev

Thursday, November 7, 13
Error Reporting: Turn it Up!
‣
Helps find existing problems
‣
Helps head off future pain
‣
Don’t say it’s just an E_NOTICE . . .
‣

Turn error reporting all the way up in dev

Thursday, November 7, 13
Error Reporting: Dev
display_errors = On
display_startup_errors = On
error_reporting = -1
log_errors = On

Thursday, November 7, 13
Error Reporting: Prod
display_errors = Off
display_startup_errors = Off
error_reporting = E_ALL
log_errors = On

Thursday, November 7, 13
Ditch NIH

Thursday, November 7, 13
Ditch NIH
‣

Thursday, November 7, 13

If you write it all yourself . . .
Ditch NIH
‣
. . . you maintain it all yourself
‣
If you write it all yourself . . .

Thursday, November 7, 13
Ditch NIH
‣
. . . you maintain it all yourself
‣
Eventually you have very little time for either . . .
‣
If you write it all yourself . . .

Thursday, November 7, 13
Real, Actual Work

Thursday, November 7, 13
Real, Actual Work

Thursday, November 7, 13
A Life

Thursday, November 7, 13
Ditch NIH

Thursday, November 7, 13
Ditch NIH
‣

Thursday, November 7, 13

Offload work to the open source community
Ditch NIH
‣
Install Composer (http://getcomposer.org)
‣

Offload work to the open source community

Thursday, November 7, 13
Ditch NIH
‣
Install Composer (http://getcomposer.org)
‣
Search Packagist (http://packagist.org)
‣

Offload work to the open source community

Thursday, November 7, 13
Ditch NIH
‣
Install Composer (http://getcomposer.org)
‣
Search Packagist (http://packagist.org)
‣
Add dependency to composer.json
‣

Offload work to the open source community

Thursday, November 7, 13
Ditch NIH
‣
Install Composer (http://getcomposer.org)
‣
Search Packagist (http://packagist.org)
‣
Add dependency to composer.json
‣
Run composer install or composer update
‣
Offload work to the open source community

Thursday, November 7, 13
Ditch NIH
‣
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.
‣
Offload work to the open source community

Thursday, November 7, 13
DRY Up Your DB

Thursday, November 7, 13
DRY Up Your DB
‣

Thursday, November 7, 13

If you’re not using PDO, switch now.
DRY Up Your DB
‣
If you’re not using prepared statements, switch now.
‣
If you’re not using PDO, switch now.

Thursday, November 7, 13
DRY Up Your DB
‣
If you’re not using prepared statements, switch now.
‣
Replace connections and queries one at a time
‣
If you’re not using PDO, switch now.

Thursday, November 7, 13
DRY Up Your DB
‣
If you’re not using prepared statements, switch now.
‣
Replace connections and queries one at a time
‣
(or one group at a time)
‣
If you’re not using PDO, switch now.

Thursday, November 7, 13
DRY Up Your DB
‣
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
‣
If you’re not using PDO, switch now.

Thursday, November 7, 13
DRY Up Your DB
class 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
DRY Up Your DB
class 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
DRY Up Your DB
class 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
DRY Up Your DB
class 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
DRY Up Your DB
class 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
Or Just Pick Something
from Packagist

Thursday, November 7, 13
Start Writing Beautiful Code

Thursday, November 7, 13
Start Writing Beautiful Code
‣

Thursday, November 7, 13

It’s time for a coding standard!
Start Writing Beautiful Code
‣
Makes life so much easier
‣

It’s time for a coding standard!

Thursday, November 7, 13
Start Writing Beautiful Code
‣
Makes life so much easier
‣
Pick someone else’s
‣

It’s time for a coding standard!

Thursday, November 7, 13
Start Writing Beautiful Code
‣
Makes life so much easier
‣
Pick someone else’s
‣
Use automated tools to enforce
‣
It’s time for a coding standard!

Thursday, November 7, 13
Start Writing Beautiful Code
‣
Makes life so much easier
‣
Pick someone else’s
‣
Use automated tools to enforce
‣
php-cs-fixer
‣
It’s time for a coding standard!

Thursday, November 7, 13
Start Writing Beautiful Code
‣
Makes life so much easier
‣
Pick someone else’s
‣
Use automated tools to enforce
‣
php-cs-fixer
‣
PHP_CodeSniffer
‣
It’s time for a coding standard!

Thursday, November 7, 13
Start Writing Beautiful Code
‣
Makes life so much easier
‣
Pick someone else’s
‣
Use automated tools to enforce
‣
php-cs-fixer
‣
PHP_CodeSniffer
‣
Refactor bit-by-bit
‣
It’s time for a coding standard!

Thursday, November 7, 13
Bonus!

Thursday, November 7, 13
PHP: The Right Way

Thursday, November 7, 13
PHP: The Right Way
‣

Thursday, November 7, 13

Go to http://www.phptherightway.com/
PHP: The Right Way
‣
Start reading
‣

Go to http://www.phptherightway.com/

Thursday, November 7, 13
PHP: The Right Way
‣
Start reading
‣
Don’t stop reading
‣

Go to http://www.phptherightway.com/

Thursday, November 7, 13
PHP: The Right Way
‣
Start reading
‣
Don’t stop reading
‣
Do it “The Right Way” for 6 months
‣

Go to http://www.phptherightway.com/

Thursday, November 7, 13
PHP: The Right Way
‣
Start reading
‣
Don’t stop reading
‣
Do it “The Right Way” for 6 months
‣
Then pick and choose
‣

Go to http://www.phptherightway.com/

Thursday, November 7, 13
Thanks!
jeremy@jeremykendall.net
http://about.me/jeremykendall
@jeremykendall
http://365.jeremykendall.net

Thursday, November 7, 13

More Related Content

PDF
Game Changing Dependency Management
PPT
XML::Liberal
PPT
Plagger the duct tape of internet
PPT
Ant Build Tool
ODP
Wordpress Security 101
PDF
톰캣 #05+b-root-deployment
PDF
Cooking with Chef
PDF
톰캣 #05+a-배치-parallel deployment
Game Changing Dependency Management
XML::Liberal
Plagger the duct tape of internet
Ant Build Tool
Wordpress Security 101
톰캣 #05+b-root-deployment
Cooking with Chef
톰캣 #05+a-배치-parallel deployment

What's hot (20)

PDF
Drupal Development : Tools, Tips, and Tricks
PPTX
There's Nothing so Permanent as Temporary
PDF
Bo0oM - There's Nothing so Permanent as Temporary (PHDays IV, 2014)
PDF
Transforming WebSockets
PDF
44CON London 2015 - reverse reverse engineering
PDF
Developing OpenResty Framework
PDF
Front-end tools
KEY
Palm Developer Day PhoneGap
PDF
Introduction to Kalabox
PDF
Ember.js Module Loading
PDF
WordPress APIs
PDF
Using React for the Mobile Web
PDF
徒手打造自己的粉專客服機器人
PDF
톰캣 #02-설치환경
PDF
Updates on Offline: “My AppCache won’t come back” and “ServiceWorker Tricks ...
PDF
Be a microservices hero
PPTX
Drupal Development Tips
PDF
Debugging PHP With Xdebug
PDF
Angular js活用事例:filydoc
PPTX
W.E.B. 2010 - Web, Exploits, Browsers
Drupal Development : Tools, Tips, and Tricks
There's Nothing so Permanent as Temporary
Bo0oM - There's Nothing so Permanent as Temporary (PHDays IV, 2014)
Transforming WebSockets
44CON London 2015 - reverse reverse engineering
Developing OpenResty Framework
Front-end tools
Palm Developer Day PhoneGap
Introduction to Kalabox
Ember.js Module Loading
WordPress APIs
Using React for the Mobile Web
徒手打造自己的粉專客服機器人
톰캣 #02-설치환경
Updates on Offline: “My AppCache won’t come back” and “ServiceWorker Tricks ...
Be a microservices hero
Drupal Development Tips
Debugging PHP With Xdebug
Angular js活用事例:filydoc
W.E.B. 2010 - Web, Exploits, Browsers
Ad

Viewers also liked (7)

ODP
PHP Quality Assurance Workshop PHPBenelux
PDF
Chatbot in Sale Management
PDF
Composer
PDF
Php & mysql course syllabus
PDF
complete Php code for a project .... (hospital management system)
PPTX
Project on PHP for Complaint management system
PPTX
ONLINE COMPLAINT MANAGEMENT SYSTEM
PHP Quality Assurance Workshop PHPBenelux
Chatbot in Sale Management
Composer
Php & mysql course syllabus
complete Php code for a project .... (hospital management system)
Project on PHP for Complaint management system
ONLINE COMPLAINT MANAGEMENT SYSTEM
Ad

Similar to 5 Ways to Awesome-ize Your (PHP) Code (20)

PDF
Android Design: Beyond the Guidelines
PDF
Multiplatform, Promises and HTML5
PDF
deSymfony 2012 - El entorno de Symfony2
PDF
TDD with LEGO at SDEC13
PDF
What Ops Can Learn From Design
PDF
Keeping it small - Getting to know the Slim PHP micro framework
PDF
SPRINT3R-SWPSDLC2556-CLOSING
PPT
3 reasons to contribute to drupal florian loretan (eng)
PDF
Software Libraries And Numbers
PDF
[Nuxeo World 2013] MARKETPLACE PACKAGES - THIBAUD ARGUILLERE
PDF
Writing SaltStack Modules - OpenWest 2013
PDF
When Tdd Goes Awry
PDF
13 Ddply
PDF
Bankers Association Communications Conference Deck
PDF
PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilid...
PDF
Show an Open Source Project Some Love and Start Using Travis-CI
PDF
Some simple tips for front-end performance in WordPress
PDF
Slaying Bugs with Gradle and Jenkins
PDF
Lessons I Learned While Scaling to 5000 Puppet Agents
Android Design: Beyond the Guidelines
Multiplatform, Promises and HTML5
deSymfony 2012 - El entorno de Symfony2
TDD with LEGO at SDEC13
What Ops Can Learn From Design
Keeping it small - Getting to know the Slim PHP micro framework
SPRINT3R-SWPSDLC2556-CLOSING
3 reasons to contribute to drupal florian loretan (eng)
Software Libraries And Numbers
[Nuxeo World 2013] MARKETPLACE PACKAGES - THIBAUD ARGUILLERE
Writing SaltStack Modules - OpenWest 2013
When Tdd Goes Awry
13 Ddply
Bankers Association Communications Conference Deck
PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilid...
Show an Open Source Project Some Love and Start Using Travis-CI
Some simple tips for front-end performance in WordPress
Slaying Bugs with Gradle and Jenkins
Lessons I Learned While Scaling to 5000 Puppet Agents

More from Jeremy Kendall (14)

PDF
Leveraging the Power of Graph Databases in PHP
PDF
Leveraging the Power of Graph Databases in PHP
ODP
Php 102: Out with the Bad, In with the Good
PDF
Keeping it Small: Getting to know the Slim Micro Framework
KEY
Keeping it small: Getting to know the Slim micro framework
KEY
Php 101: PDO
ODP
PHP 102: Out with the Bad, In with the Good
ODP
Intro to #memtech PHP 2011-12-05
ODP
TDD in PHP - Memphis PHP 2011-08-25
ODP
Zend_Form to the Rescue - A Brief Introduction to Zend_Form
PDF
Zero to ZF in 10 Minutes
ODP
Tdd in php a brief example
ODP
A Brief Introduction to Zend_Form
ODP
Zero to Zend Framework in 10 minutes
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
Php 102: Out with the Bad, In with the Good
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it small: Getting to know the Slim micro framework
Php 101: PDO
PHP 102: Out with the Bad, In with the Good
Intro to #memtech PHP 2011-12-05
TDD in PHP - Memphis PHP 2011-08-25
Zend_Form to the Rescue - A Brief Introduction to Zend_Form
Zero to ZF in 10 Minutes
Tdd in php a brief example
A Brief Introduction to Zend_Form
Zero to Zend Framework in 10 minutes

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PDF
Electronic commerce courselecture one. Pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
KodekX | Application Modernization Development
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Machine learning based COVID-19 study performance prediction
PDF
cuic standard and advanced reporting.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
NewMind AI Monthly Chronicles - July 2025
Cloud computing and distributed systems.
Electronic commerce courselecture one. Pdf
Understanding_Digital_Forensics_Presentation.pptx
Review of recent advances in non-invasive hemoglobin estimation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KodekX | Application Modernization Development
Network Security Unit 5.pdf for BCA BBA.
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Building Integrated photovoltaic BIPV_UPV.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation theory and applications.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Machine learning based COVID-19 study performance prediction
cuic standard and advanced reporting.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
NewMind AI Weekly Chronicles - August'25 Week I
Chapter 3 Spatial Domain Image Processing.pdf
Empathic Computing: Creating Shared Understanding
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Monthly Chronicles - July 2025

5 Ways to Awesome-ize Your (PHP) Code

  • 1. 5 Ways to Awesome-ize Your (PHP) Code Jeremy Kendall Thursday, November 7, 13
  • 3. I love to code Thursday, November 7, 13
  • 4. I love to code I’m terribly forgetful Thursday, November 7, 13
  • 5. I love to code I’m terribly forgetful I take pictures Thursday, November 7, 13
  • 6. I love to code I’m terribly forgetful I take pictures I work at OpenSky Thursday, November 7, 13
  • 7. What Are These 5 Ways of Which You Speak? Thursday, November 7, 13
  • 9. Use Version Control ‣ Thursday, November 7, 13 If you aren’t using version control, use git
  • 10. Use Version Control ‣ If you aren’t using version control, use git Install git Thursday, November 7, 13
  • 11. Use Version Control ‣ If you aren’t using version control, use git Install git cd /path/to/project Thursday, November 7, 13
  • 12. Use Version Control ‣ If you aren’t using version control, use git Install git cd /path/to/project git init Thursday, November 7, 13
  • 13. 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
  • 14. 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
  • 15. 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 Interactive tutorial at http://try.github.io
  • 16. or Else . . . Thursday, November 7, 13
  • 17. Error Reporting: Turn it Up! Thursday, November 7, 13
  • 18. Error Reporting: Turn it Up! ‣ Thursday, November 7, 13 Turn error reporting all the way up in dev
  • 19. Error Reporting: Turn it Up! ‣ Helps find existing problems ‣ Turn error reporting all the way up in dev Thursday, November 7, 13
  • 20. Error Reporting: Turn it Up! ‣ Helps find existing problems ‣ Helps head off future pain ‣ Turn error reporting all the way up in dev Thursday, November 7, 13
  • 21. Error Reporting: Turn it Up! ‣ Helps find existing problems ‣ Helps head off future pain ‣ Don’t say it’s just an E_NOTICE . . . ‣ Turn error reporting all the way up in dev Thursday, November 7, 13
  • 22. Error Reporting: Turn it Up! ‣ Helps find existing problems ‣ Helps head off future pain ‣ Don’t say it’s just an E_NOTICE . . . ‣ Turn error reporting all the way up in dev Thursday, November 7, 13
  • 23. Error Reporting: Dev display_errors = On display_startup_errors = On error_reporting = -1 log_errors = On Thursday, November 7, 13
  • 24. Error Reporting: Prod display_errors = Off display_startup_errors = Off error_reporting = E_ALL log_errors = On Thursday, November 7, 13
  • 26. Ditch NIH ‣ Thursday, November 7, 13 If you write it all yourself . . .
  • 27. Ditch NIH ‣ . . . you maintain it all yourself ‣ If you write it all yourself . . . Thursday, November 7, 13
  • 28. Ditch NIH ‣ . . . you maintain it all yourself ‣ Eventually you have very little time for either . . . ‣ If you write it all yourself . . . Thursday, November 7, 13
  • 29. Real, Actual Work Thursday, November 7, 13
  • 30. Real, Actual Work Thursday, November 7, 13
  • 33. Ditch NIH ‣ Thursday, November 7, 13 Offload work to the open source community
  • 34. Ditch NIH ‣ Install Composer (http://getcomposer.org) ‣ Offload work to the open source community Thursday, November 7, 13
  • 35. Ditch NIH ‣ Install Composer (http://getcomposer.org) ‣ Search Packagist (http://packagist.org) ‣ Offload work to the open source community Thursday, November 7, 13
  • 36. Ditch NIH ‣ Install Composer (http://getcomposer.org) ‣ Search Packagist (http://packagist.org) ‣ Add dependency to composer.json ‣ Offload work to the open source community Thursday, November 7, 13
  • 37. Ditch NIH ‣ Install Composer (http://getcomposer.org) ‣ Search Packagist (http://packagist.org) ‣ Add dependency to composer.json ‣ Run composer install or composer update ‣ Offload work to the open source community Thursday, November 7, 13
  • 38. Ditch NIH ‣ 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. ‣ Offload work to the open source community Thursday, November 7, 13
  • 39. DRY Up Your DB Thursday, November 7, 13
  • 40. DRY Up Your DB ‣ Thursday, November 7, 13 If you’re not using PDO, switch now.
  • 41. DRY Up Your DB ‣ If you’re not using prepared statements, switch now. ‣ If you’re not using PDO, switch now. Thursday, November 7, 13
  • 42. DRY Up Your DB ‣ If you’re not using prepared statements, switch now. ‣ Replace connections and queries one at a time ‣ If you’re not using PDO, switch now. Thursday, November 7, 13
  • 43. DRY Up Your DB ‣ If you’re not using prepared statements, switch now. ‣ Replace connections and queries one at a time ‣ (or one group at a time) ‣ If you’re not using PDO, switch now. Thursday, November 7, 13
  • 44. DRY Up Your DB ‣ 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 ‣ If you’re not using PDO, switch now. Thursday, November 7, 13
  • 45. DRY Up Your DB class 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
  • 46. DRY Up Your DB class 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
  • 47. DRY Up Your DB class 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
  • 48. DRY Up Your DB class 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
  • 49. DRY Up Your DB class 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
  • 50. Or Just Pick Something from Packagist Thursday, November 7, 13
  • 51. Start Writing Beautiful Code Thursday, November 7, 13
  • 52. Start Writing Beautiful Code ‣ Thursday, November 7, 13 It’s time for a coding standard!
  • 53. Start Writing Beautiful Code ‣ Makes life so much easier ‣ It’s time for a coding standard! Thursday, November 7, 13
  • 54. Start Writing Beautiful Code ‣ Makes life so much easier ‣ Pick someone else’s ‣ It’s time for a coding standard! Thursday, November 7, 13
  • 55. Start Writing Beautiful Code ‣ Makes life so much easier ‣ Pick someone else’s ‣ Use automated tools to enforce ‣ It’s time for a coding standard! Thursday, November 7, 13
  • 56. Start Writing Beautiful Code ‣ Makes life so much easier ‣ Pick someone else’s ‣ Use automated tools to enforce ‣ php-cs-fixer ‣ It’s time for a coding standard! Thursday, November 7, 13
  • 57. Start Writing Beautiful Code ‣ Makes life so much easier ‣ Pick someone else’s ‣ Use automated tools to enforce ‣ php-cs-fixer ‣ PHP_CodeSniffer ‣ It’s time for a coding standard! Thursday, November 7, 13
  • 58. Start Writing Beautiful Code ‣ Makes life so much easier ‣ Pick someone else’s ‣ Use automated tools to enforce ‣ php-cs-fixer ‣ PHP_CodeSniffer ‣ Refactor bit-by-bit ‣ It’s time for a coding standard! Thursday, November 7, 13
  • 60. PHP: The Right Way Thursday, November 7, 13
  • 61. PHP: The Right Way ‣ Thursday, November 7, 13 Go to http://www.phptherightway.com/
  • 62. PHP: The Right Way ‣ Start reading ‣ Go to http://www.phptherightway.com/ Thursday, November 7, 13
  • 63. PHP: The Right Way ‣ Start reading ‣ Don’t stop reading ‣ Go to http://www.phptherightway.com/ Thursday, November 7, 13
  • 64. PHP: The Right Way ‣ Start reading ‣ Don’t stop reading ‣ Do it “The Right Way” for 6 months ‣ Go to http://www.phptherightway.com/ Thursday, November 7, 13
  • 65. PHP: The Right Way ‣ Start reading ‣ Don’t stop reading ‣ Do it “The Right Way” for 6 months ‣ Then pick and choose ‣ Go to http://www.phptherightway.com/ Thursday, November 7, 13