Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

GeekAustin PHP Class - Session 6

1,321 views

Published on

  • Be the first to comment

GeekAustin PHP Class - Session 6

  1. 1. Beginning PHP Session #6 January 5, 2011 Josh Butts
  2. 2. Agenda • Freebies from Zend • OOP
  3. 3. What are Objects • Programming constructs • Represent a real-life entity • Store data (state) • Implement behaviors
  4. 4. Object Oriented Programming • ...programming with objects • Use objects to model real world concepts in your code • Objects encapsulate pieces of logic or data • Objects are easy to re-use
  5. 5. Terms • Class - the definition of an object; what does it represent, what can it do • Instance - an actual object variable in memory
  6. 6. Classes & Instances • A class is defined in code as you write your program • An instance happens when you program actually runs
  7. 7. Example User Class Instance of User $username $password jimbojsb $email password $firstname josh@joshbutts.com $lastname Josh Butts authenticate() createPassword() getPosts()
  8. 8. Classes & Instances • A class is defined in code as you write your program • An instance happens when you program actually runs
  9. 9. “Static” • Static describes a class or part of a class that can be used without actually creating an instance and filling it with data • Pieces of data that are the same for every instance of a class • Logic that operates on generic data rather than modifying a specific instance’s state
  10. 10. Building Objects • Properties (variables) • Methods (functions) • Methods & Properties can both be static or not
  11. 11. Constructors • A special method (1 per object) that gets called when you get a new instance • Does any utility or setup work needed before the instance is ready to be used • Optional • Usually take one or more parameters
  12. 12. PHP Objects • Preferably you define one class per file • Objects are always passed by reference instead of by value • :: operator is used for static properties and methods • -> operator is used for instance properties and methods
  13. 13. PHP Objects • self - refers to the current object in a static manner • $this - refers to the current instance
  14. 14. Special Methods • __construct() • __destruct() • __toString() • many others, for a later discussion

×