SlideShare a Scribd company logo
Beginning PHP
     Session #6
   January 5, 2011
     Josh Butts
Agenda


• Freebies from Zend
• OOP
What are Objects

• Programming constructs
• Represent a real-life entity
• Store data (state)
• Implement behaviors
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
Terms

• Class - the definition of an object; what
  does it represent, what can it do
• Instance - an actual object variable in
  memory
Classes & Instances

• A class is defined in code as you write your
  program
• An instance happens when you program
  actually runs
Example
   User Class
                             Instance of User
  $username
  $password
                              jimbojsb
    $email
                              password
  $firstname
                         josh@joshbutts.com
  $lastname
                                 Josh
                                Butts
  authenticate()
createPassword()
    getPosts()
Classes & Instances

• A class is defined in code as you write your
  program
• An instance happens when you program
  actually runs
“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
Building Objects
• Properties (variables)

• Methods (functions)

• Methods & Properties can both be static or
  not
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
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
PHP Objects


• self - refers to the current object in a static
  manner
• $this - refers to the current instance
Special Methods

• __construct()
• __destruct()
• __toString()
• many others, for a later discussion

More Related Content

PPTX
Moo the universe and everything
PPTX
[OOP - Lec 04,05] Basic Building Blocks of OOP
PPTX
Introduction to java
PPTX
Lec02 primitive types
DOCX
Object oriented programming tutorial
PPTX
Object Oriented Programming
PPT
Geek Austin PHP Class - Session 2
PPTX
[OOP - Lec 06] Classes and Objects
Moo the universe and everything
[OOP - Lec 04,05] Basic Building Blocks of OOP
Introduction to java
Lec02 primitive types
Object oriented programming tutorial
Object Oriented Programming
Geek Austin PHP Class - Session 2
[OOP - Lec 06] Classes and Objects

What's hot (14)

PPT
Introduction what is java
PPTX
Intro to java programming
PPTX
02 beginning code first
PDF
New design patterns
PPT
PPT
Java intro
PPT
RIBBUN SOFTWARE
PPT
Java01
PPT
java-corporate-training-institute-in-mumbai
PPTX
Introduction to oop and java fundamentals
PDF
Java for android developers
PPTX
Code reviews
PPTX
Introduction what is java
Intro to java programming
02 beginning code first
New design patterns
Java intro
RIBBUN SOFTWARE
Java01
java-corporate-training-institute-in-mumbai
Introduction to oop and java fundamentals
Java for android developers
Code reviews
Ad

Viewers also liked (11)

KEY
GeekAustin PHP Class - Session 7
KEY
Fall 2011 PHP Class - Session 1
PDF
Geek Austin PHP Class - Session 1
KEY
Fall 2011 PHP Class - Session 2
KEY
Austin NoSQL 2011-07-06
PPT
Geek Austin PHP Class - Session 3
PPT
Geek Austin PHP Class - Session 4
PDF
Security in php
KEY
Scaling php applications with redis
PPT
Php ssession - cookies -introduction
PPTX
Session php
GeekAustin PHP Class - Session 7
Fall 2011 PHP Class - Session 1
Geek Austin PHP Class - Session 1
Fall 2011 PHP Class - Session 2
Austin NoSQL 2011-07-06
Geek Austin PHP Class - Session 3
Geek Austin PHP Class - Session 4
Security in php
Scaling php applications with redis
Php ssession - cookies -introduction
Session php
Ad

Similar to GeekAustin PHP Class - Session 6 (20)

PPTX
ppt_on_java.pptx
PDF
Javascript classes and scoping
PDF
Никита Корчагин - Programming Apple iOS with Objective-C
PDF
Google App Engine - exploiting limitations
KEY
Preliminary committee presentation
PPTX
Real World MVC
PPTX
Object Oriented Programming - Copy.pptxb
PPSX
OOPS Concepts in Python and Exception Handling
PPTX
OOPs fundamentals session for freshers in my office (Aug 5, 13)
PDF
Entity API in Drupal 8 (Drupal Tech Talk October 2014)
PPTX
Build your datatypes
PDF
Entities in Drupal 8 - Drupal Tech Talk - Bart Feenstra
PPTX
Object Oriented Programming Tutorial.pptx
PDF
12. Objects I
PPTX
Introduction to OOP with java
PPTX
Object Oriented Programming Class and Objects
PPT
Object Oriented PHP Overview
PPTX
introduction_OOP for the java courses [Autosaved].pptx
PPT
Power of introspection
PPTX
introduction of Object oriented programming
ppt_on_java.pptx
Javascript classes and scoping
Никита Корчагин - Programming Apple iOS with Objective-C
Google App Engine - exploiting limitations
Preliminary committee presentation
Real World MVC
Object Oriented Programming - Copy.pptxb
OOPS Concepts in Python and Exception Handling
OOPs fundamentals session for freshers in my office (Aug 5, 13)
Entity API in Drupal 8 (Drupal Tech Talk October 2014)
Build your datatypes
Entities in Drupal 8 - Drupal Tech Talk - Bart Feenstra
Object Oriented Programming Tutorial.pptx
12. Objects I
Introduction to OOP with java
Object Oriented Programming Class and Objects
Object Oriented PHP Overview
introduction_OOP for the java courses [Autosaved].pptx
Power of introspection
introduction of Object oriented programming

GeekAustin PHP Class - Session 6

  • 1. Beginning PHP Session #6 January 5, 2011 Josh Butts
  • 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
  • 10. Building Objects • Properties (variables) • Methods (functions) • Methods & Properties can both be static or not
  • 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
  • 14. Special Methods • __construct() • __destruct() • __toString() • many others, for a later discussion