3. What are Objects
• Programming constructs
• Represent a real-life entity
• Store data (state)
• Implement behaviors
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. Terms
• Class - the definition of an object; what
does it represent, what can it do
• Instance - an actual object variable in
memory
6. Classes & Instances
• A class is defined in code as you write your
program
• An instance happens when you program
actually runs
7. Example
User Class
Instance of User
$username
$password
jimbojsb
$email
password
$firstname
josh@joshbutts.com
$lastname
Josh
Butts
authenticate()
createPassword()
getPosts()
8. Classes & Instances
• A class is defined in code as you write your
program
• An instance happens when you program
actually runs
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
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. 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. PHP Objects
• self - refers to the current object in a static
manner
• $this - refers to the current instance