<ul><li>The Current Situation </li></ul><ul><li>Object-Oriented Introduction </li></ul><ul><ul><li>Basics, concepts, termi...
<ul><li>Most scripts & tutorials all procedural or show bad understanding of OO </li></ul><ul><li>PHP’s unique history </l...
 
That was easy! Add “Object-Oriented PHP” to your resume!
<ul><li>It’s much more than just syntax –  It’s a mindset </li></ul><ul><li>Object-Oriented programming gives  meaning  to...
<ul><li>Semantic markup </li></ul><ul><li>Think: </li></ul><ul><ul><li><blockquote> for quotes, not indentation </li></ul>...
<ul><li>Create meaning and structure </li></ul><ul><li>Separate responsibilities </li></ul><ul><li>Reduce/Isolate dependen...
<ul><li>Code objects cannot  always  represent real-world objects </li></ul><ul><ul><li>Application flow </li></ul></ul><u...
<ul><li>Model-View-Controller (MVC) </li></ul><ul><li>Active Record </li></ul><ul><li>Data Mapper </li></ul><ul><li>Adapte...
<ul><li>What OO programming is  not  – where many PHP projects go wrong </li></ul>
 
<ul><li>Decorator </li></ul>
<ul><li>What is User? </li></ul><ul><ul><li>A finder/utility class? </li></ul></ul><ul><ul><li>No clear definition or purp...
<ul><li>The power of applying object-oriented design to your application </li></ul>
<ul><li>Objects add automatic clarity </li></ul><ul><li>Stick to standards and naming conventions </li></ul><ul><ul><li>ca...
 
 
 
<ul><li>Parent > Child relationship between objects </li></ul><ul><ul><li>Child extends Parent </li></ul></ul><ul><li>Chil...
 
<ul><li>Hides actual implementation </li></ul><ul><li>Reduces or isolates dependencies to lower levels </li></ul><ul><li>R...
<ul><ul><li>Adding extra headers is a mess (CC, BCC) </li></ul></ul><ul><ul><li>No built-in file attachment options </li><...
<ul><ul><li>Custom Email() object </li></ul></ul><ul><ul><li>Clear, descriptive syntax </li></ul></ul><ul><ul><li>Unlimite...
Did you notice the dependencies?
<ul><li>Remove the database dependencies by using a standard interface </li></ul><ul><ul><li>PDO provides one (bundled wit...
Pass connection into constructor and store it as a class property Replace mysql_* functions with standard functions from P...
Database adapters are interchangeable
<ul><li>Interchangeable code components </li></ul><ul><ul><li>Standard interface </li></ul></ul><ul><ul><li>Single depende...
Different payment processors are a simple drop-in replacement
<ul><li>Objects should serve a single purpose </li></ul><ul><ul><li>Separate code into manageable chunks </li></ul></ul><u...
 
 
<ul><li>Building a Data Mapper with PHP5 and the Standard PHP Library </li></ul><ul><ul><li>Friday Oct. 10 @ 10:30am </li>...
<ul><li>www.php.net/php5 </li></ul><ul><ul><li>Full official PHP5 feature documentation </li></ul></ul><ul><li>Communities...
<ul><li>Vance Lucas, 23 </li></ul><ul><ul><li>Blog:  www.vancelucas.com </li></ul></ul><ul><ul><li>Email:  [email_address]...
 
Upcoming SlideShare
Loading in...5
×

PHP - Procedural To Object-Oriented

19,985
-1

Published on

Learn the power of object-oriented programming in PHP5 and the many benefits it offers over the more traditional PHP procedural programming style. This session will include a light introduction to object-oriented concepts and will provide real-world concrete examples of the benefits it can offer you and the PHP projects you work on.

Published in: Technology
4 Comments
15 Likes
Statistics
Notes
  • Good presentation
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • This is utter rubbish, I'm sorry but I code php in a procedural way and it is alot faster and more scalable than an OOP approach. Just as a quick example I recently converted (for a client) a smarty OOP approach to a procedural approach. The smarty was averaging about 6 seconds load time for a page and killing the CPU of the server - the OOP was also very long and cumbersome and not easy to identify when working on someone else's code... I took it to procedural and shaved 5 seconds from the load time, 98% off the CPU load and the site is now manageable with clearlrly documented functions.

    This slideshow is full of holes (security and memory) - whether or not these are intentional I don;t know but perhaps show some secure programming when demonstrating the so called 'power' or OOP in php.

    Don't get me wrong .. OOP has it's place in programming but it certainly for the enterprise projects I write it is not better than procedural programming.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Goof presentation.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • thanks, very helpful
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
19,985
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
501
Comments
4
Likes
15
Embeds 0
No embeds

No notes for slide

PHP - Procedural To Object-Oriented

  1. 2. <ul><li>The Current Situation </li></ul><ul><li>Object-Oriented Introduction </li></ul><ul><ul><li>Basics, concepts, terminology & examples </li></ul></ul><ul><li>Object-Oriented Benefits </li></ul><ul><ul><li>Code re-use, portability, structure, meaning, control, separation of responsibility, time, reduce dependencies and more </li></ul></ul>
  2. 3. <ul><li>Most scripts & tutorials all procedural or show bad understanding of OO </li></ul><ul><li>PHP’s unique history </li></ul><ul><ul><li>Template language & PHP/FI 2.0 </li></ul></ul><ul><ul><li>“ evolved” over time with OO features </li></ul></ul><ul><li>Good OO finally starting to emerge </li></ul><ul><ul><li>PHP5 released in 2004 </li></ul></ul><ul><ul><li>Zend Framework </li></ul></ul><ul><ul><li>Symfony Project </li></ul></ul>
  3. 5. That was easy! Add “Object-Oriented PHP” to your resume!
  4. 6. <ul><li>It’s much more than just syntax – It’s a mindset </li></ul><ul><li>Object-Oriented programming gives meaning to your data </li></ul><ul><ul><li>Represents real-world objects when possible </li></ul></ul><ul><li>Where have we seen this before? </li></ul>
  5. 7. <ul><li>Semantic markup </li></ul><ul><li>Think: </li></ul><ul><ul><li><blockquote> for quotes, not indentation </li></ul></ul><ul><ul><li><address> for addresses, not <p> or <div> </li></ul></ul><ul><ul><li><cite> instead of <i> for citations </li></ul></ul><ul><li>Goal is to for code to convey meaning </li></ul>
  6. 8. <ul><li>Create meaning and structure </li></ul><ul><li>Separate responsibilities </li></ul><ul><li>Reduce/Isolate dependencies </li></ul><ul><li>Create common public interfaces </li></ul><ul><li>Clear, self-documenting code </li></ul>
  7. 9. <ul><li>Code objects cannot always represent real-world objects </li></ul><ul><ul><li>Application flow </li></ul></ul><ul><ul><li>Structure </li></ul></ul><ul><ul><li>Delegation </li></ul></ul><ul><ul><li>Separation of responsibilities </li></ul></ul><ul><li>How do we solve these problems? </li></ul><ul><ul><li>Design Patterns </li></ul></ul>
  8. 10. <ul><li>Model-View-Controller (MVC) </li></ul><ul><li>Active Record </li></ul><ul><li>Data Mapper </li></ul><ul><li>Adapter </li></ul><ul><li>Registry </li></ul><ul><li>Factory </li></ul><ul><li>Observer </li></ul>
  9. 11. <ul><li>What OO programming is not – where many PHP projects go wrong </li></ul>
  10. 13. <ul><li>Decorator </li></ul>
  11. 14. <ul><li>What is User? </li></ul><ul><ul><li>A finder/utility class? </li></ul></ul><ul><ul><li>No clear definition or purpose </li></ul></ul><ul><li>“ bob” is a User </li></ul><ul><ul><li>1 instance = 1 user </li></ul></ul><ul><ul><li>Properties of a user </li></ul></ul><ul><ul><li>Functions of a user </li></ul></ul>
  12. 15. <ul><li>The power of applying object-oriented design to your application </li></ul>
  13. 16. <ul><li>Objects add automatic clarity </li></ul><ul><li>Stick to standards and naming conventions </li></ul><ul><ul><li>camelCase </li></ul></ul><ul><ul><li>Zend Coding Standards </li></ul></ul><ul><li>Function naming as verbose as possible </li></ul><ul><ul><li>getPostBySlug($slug) </li></ul></ul><ul><ul><li>findPostsWithTag($tagName) </li></ul></ul>
  14. 20. <ul><li>Parent > Child relationship between objects </li></ul><ul><ul><li>Child extends Parent </li></ul></ul><ul><li>Child inherits all parent methods </li></ul><ul><ul><li>Child can override parent methods when required </li></ul></ul><ul><li>Changes can be reflected across your entire application with relative ease </li></ul>
  15. 22. <ul><li>Hides actual implementation </li></ul><ul><li>Reduces or isolates dependencies to lower levels </li></ul><ul><li>Reduces or eliminates extensive future changes in code base </li></ul>
  16. 23. <ul><ul><li>Adding extra headers is a mess (CC, BCC) </li></ul></ul><ul><ul><li>No built-in file attachment options </li></ul></ul><ul><ul><li>Limited configuration options (Sendmail/SMTP) </li></ul></ul><ul><ul><li>Very inefficient for large amounts of email </li></ul></ul>
  17. 24. <ul><ul><li>Custom Email() object </li></ul></ul><ul><ul><li>Clear, descriptive syntax </li></ul></ul><ul><ul><li>Unlimited configuration options </li></ul></ul><ul><ul><ul><li>mail(), SMTP, database, external server, etc. </li></ul></ul></ul><ul><ul><li>File attachments can be easy with function </li></ul></ul>
  18. 25. Did you notice the dependencies?
  19. 26. <ul><li>Remove the database dependencies by using a standard interface </li></ul><ul><ul><li>PDO provides one (bundled with PHP5) </li></ul></ul><ul><li>Use dependency injection to expose dependencies </li></ul>
  20. 27. Pass connection into constructor and store it as a class property Replace mysql_* functions with standard functions from PDO using connection
  21. 28. Database adapters are interchangeable
  22. 29. <ul><li>Interchangeable code components </li></ul><ul><ul><li>Standard interface </li></ul></ul><ul><ul><li>Single dependency </li></ul></ul><ul><li>Separate “engine” from implementation </li></ul>
  23. 30. Different payment processors are a simple drop-in replacement
  24. 31. <ul><li>Objects should serve a single purpose </li></ul><ul><ul><li>Separate code into manageable chunks </li></ul></ul><ul><li>MVC – Good example </li></ul><ul><ul><li>Model – Database </li></ul></ul><ul><ul><li>View – Display </li></ul></ul><ul><ul><li>Controller – Request/Flow </li></ul></ul><ul><li>Resist temptation of globals everywhere </li></ul><ul><ul><li>“ global $var”, $_SESSION, $_REQUEST, etc </li></ul></ul>
  25. 34. <ul><li>Building a Data Mapper with PHP5 and the Standard PHP Library </li></ul><ul><ul><li>Friday Oct. 10 @ 10:30am </li></ul></ul>
  26. 35. <ul><li>www.php.net/php5 </li></ul><ul><ul><li>Full official PHP5 feature documentation </li></ul></ul><ul><li>Communities </li></ul><ul><ul><li>Sitepoint – sitepoint.com </li></ul></ul><ul><ul><li>PHPit – phpit.com </li></ul></ul><ul><ul><li>PHP|Architect – phparch.com </li></ul></ul><ul><ul><li>Zend Developer Zone - devzone.zend.com </li></ul></ul>
  27. 36. <ul><li>Vance Lucas, 23 </li></ul><ul><ul><li>Blog: www.vancelucas.com </li></ul></ul><ul><ul><li>Email: [email_address] </li></ul></ul><ul><li>Making websites since age 12 </li></ul><ul><ul><li>Started learning PHP when PHP3 was new </li></ul></ul><ul><li>Oklahoma Baptist University – Shawee </li></ul><ul><ul><li>Bachelor of Business Administration </li></ul></ul><ul><li>Currently work at Back40 Design, Inc. </li></ul><ul><ul><li>www.back40design.com </li></ul></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×