SlideShare ist ein Scribd-Unternehmen logo
1 von 14
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

Weitere ähnliche Inhalte

Was ist angesagt? (14)

Introduction what is java
Introduction what is javaIntroduction what is java
Introduction what is java
 
Intro to java programming
Intro to java programmingIntro to java programming
Intro to java programming
 
02 beginning code first
02   beginning code first02   beginning code first
02 beginning code first
 
New design patterns
New design patternsNew design patterns
New design patterns
 
Java
JavaJava
Java
 
Java intro
Java introJava intro
Java intro
 
RIBBUN SOFTWARE
RIBBUN SOFTWARERIBBUN SOFTWARE
RIBBUN SOFTWARE
 
Java01
Java01Java01
Java01
 
Java
JavaJava
Java
 
java-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbaijava-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbai
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentals
 
Java for android developers
Java for android developersJava for android developers
Java for android developers
 
Code reviews
Code reviewsCode reviews
Code reviews
 
TypeScript
TypeScriptTypeScript
TypeScript
 

Andere mochten auch (11)

GeekAustin PHP Class - Session 7
GeekAustin PHP Class - Session 7GeekAustin PHP Class - Session 7
GeekAustin PHP Class - Session 7
 
Fall 2011 PHP Class - Session 1
Fall 2011 PHP Class - Session 1Fall 2011 PHP Class - Session 1
Fall 2011 PHP Class - Session 1
 
Geek Austin PHP Class - Session 1
Geek Austin PHP Class - Session 1Geek Austin PHP Class - Session 1
Geek Austin PHP Class - Session 1
 
Fall 2011 PHP Class - Session 2
Fall 2011 PHP Class - Session 2Fall 2011 PHP Class - Session 2
Fall 2011 PHP Class - Session 2
 
Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06
 
Geek Austin PHP Class - Session 3
Geek Austin PHP Class - Session 3Geek Austin PHP Class - Session 3
Geek Austin PHP Class - Session 3
 
Geek Austin PHP Class - Session 4
Geek Austin PHP Class - Session 4Geek Austin PHP Class - Session 4
Geek Austin PHP Class - Session 4
 
Security in php
Security in phpSecurity in php
Security in php
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introduction
 
Session php
Session phpSession php
Session php
 

Ähnlich wie GeekAustin PHP Class - Session 6

Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-C
DataArt
 
Google App Engine - exploiting limitations
Google App Engine - exploiting limitationsGoogle App Engine - exploiting limitations
Google App Engine - exploiting limitations
Tomáš Holas
 
Build your datatypes
Build your datatypesBuild your datatypes
Build your datatypes
Edi Modrić
 
Object Oriented PHP Overview
Object Oriented PHP OverviewObject Oriented PHP Overview
Object Oriented PHP Overview
Larry Ball
 
Power of introspection
Power of introspectionPower of introspection
Power of introspection
Joseph Jeffrey
 
Python Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsPython Programming - VI. Classes and Objects
Python Programming - VI. Classes and Objects
Ranel Padon
 

Ähnlich wie GeekAustin PHP Class - Session 6 (20)

ppt_on_java.pptx
ppt_on_java.pptxppt_on_java.pptx
ppt_on_java.pptx
 
Javascript classes and scoping
Javascript classes and scopingJavascript classes and scoping
Javascript classes and scoping
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-C
 
Google App Engine - exploiting limitations
Google App Engine - exploiting limitationsGoogle App Engine - exploiting limitations
Google App Engine - exploiting limitations
 
Preliminary committee presentation
Preliminary committee presentationPreliminary committee presentation
Preliminary committee presentation
 
Real World MVC
Real World MVCReal World MVC
Real World MVC
 
OOPs fundamentals session for freshers in my office (Aug 5, 13)
OOPs fundamentals session for freshers in my office (Aug 5, 13)OOPs fundamentals session for freshers in my office (Aug 5, 13)
OOPs fundamentals session for freshers in my office (Aug 5, 13)
 
Entity API in Drupal 8 (Drupal Tech Talk October 2014)
Entity API in Drupal 8 (Drupal Tech Talk October 2014)Entity API in Drupal 8 (Drupal Tech Talk October 2014)
Entity API in Drupal 8 (Drupal Tech Talk October 2014)
 
Build your datatypes
Build your datatypesBuild your datatypes
Build your datatypes
 
Entities in Drupal 8 - Drupal Tech Talk - Bart Feenstra
Entities in Drupal 8 - Drupal Tech Talk - Bart FeenstraEntities in Drupal 8 - Drupal Tech Talk - Bart Feenstra
Entities in Drupal 8 - Drupal Tech Talk - Bart Feenstra
 
Object Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptxObject Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptx
 
12. Objects I
12. Objects I12. Objects I
12. Objects I
 
Introduction to OOP with java
Introduction to OOP with javaIntroduction to OOP with java
Introduction to OOP with java
 
Object Oriented PHP Overview
Object Oriented PHP OverviewObject Oriented PHP Overview
Object Oriented PHP Overview
 
Power of introspection
Power of introspectionPower of introspection
Power of introspection
 
introduction of Object oriented programming
introduction of Object oriented programmingintroduction of Object oriented programming
introduction of Object oriented programming
 
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuery
 
Lecture 1 - Objects and classes
Lecture 1 - Objects and classesLecture 1 - Objects and classes
Lecture 1 - Objects and classes
 
About Python
About PythonAbout Python
About Python
 
Python Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsPython Programming - VI. Classes and Objects
Python Programming - VI. Classes and Objects
 

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