SlideShare a Scribd company logo
WELCOME TO ‘INTRO TO OOP WITH PHP’
Thank you for your interest. Files can be found at https://
github.com/sketchings/oop-basics
Contact Info:
www.sketchings.com
@sketchings
alena@holligan.us
INTRO TO OOP WITH PHP (INTRODUCTION)
A BASIC LOOK INTO OBJECT-ORIENTED PROGRAMMING
WHAT IS OOP?
➔Object-Oriented Programing
➔A programming concept that treats functions and
data as objects.
➔A programming methodology based on objects,
instead of functions and procedures
OOP VS PROCEDURAL OR FUNCTIONAL
• OOP is built around the "nouns", the things in the
system, and what they are capable of
• Whereas procedural or functional programming
is built around the "verbs" of the system, the
things you want the system to do
LET’S GET INTO SOME EXAMPLES
Files can be found at https://github.com/
sketchings/oop-basics
Contact Info:
www.sketchings.com
@sketchings
alena@holligan.us
WELCOME TO ‘INTRO TO OOP WITH PHP’
PART 1
Thank you for your interest. Files can be found at https://
github.com/sketchings/oop-basics
Contact Info:
www.sketchings.com
@sketchings
alena@holligan.us
INTRO TO OOP WITH PHP (PART 1)
A BASIC LOOK INTO OBJECT-ORIENTED PROGRAMMING
TERMINOLOGY
THE SINGLE MOST IMPORTANT PART
TERMS
• Class (properties, methods)
• Object
• Instance
• Abstraction
• Encapsulation
• Inheritance
CLASS
• A template/blueprint that facilitates creation of objects.
A set of program statements to do a certain task. Usually
represents a noun, such as a person, place or thing.
• Includes properties and methods — which are class
functions
OBJECT
• Instance of a class.
• In the real world object is a material thing that
can be seen and touched.
• In OOP, object is a self-contained entity that
consists of both data and procedures.
INSTANCE
• Single occurrence/copy of an object
• There might be one or several objects, but an
instance is a specific copy, to which you can have
a reference
class User { //class
private $name; //property
public getName() { //method
echo $this->name;
}
}
$user1 = new User(); //first instance of object
$user2 = new User(); //second instance of object
ABSTRACTION
• “An abstraction denotes the essential characteristics
of an object that distinguish it from all other kinds of
object and thus provide crisply defined conceptual
boundaries, relative to the perspective of the viewer.”

— G. Booch
• This is the class architecture itself.
ENCAPSULATION
• Scope. Controls who can access what. Restricting
access to some of the object’s components (properties
and methods), preventing unauthorized access.
• Public - everyone
• Protected - inherited classes
• Private - class itself, not children
• class User {

protected $name;

protected $title;

public function getFormattedSalutation() {

return $this->getSalutation();

}

protected function getSalutation() {

return $this->title . " " . $this->name;

}

public function getName() {

return $this->name;

}

public function setName($name) {

$this->name = $name;

}

public function getTitle() {

return $this->title;

}

public function setTitle($title) {

$this->title = $title;

}

}
CREATING / USING THE OBJECT INSTANCE
$user = new User();

$user->setName("Jane Smith");

$user->setTitle("Ms");

echo $user->getFormattedSalutation();
When the script is run, it will return:
Ms Jane Smith
CONSTRUCTOR METHOD & MAGIC METHODS
class User {

protected $name;

protected $title;



public function __construct($name, $title) {

$this->name = $name;

$this->title = $title;

}



public function __toString() {

return $this->getFormattedSalutation();

}

...

}
For more see http://php.net/manual/en/language.oop5.magic.php
CREATING / USING THE OBJECT INSTANCE
$user = new User("Jane Smith","Ms");

echo $user;
When the script is run, it will return the same result as before:
Ms Jane Smith
INHERITANCE: PASSES KNOWLEDGE DOWN
• Subclass, parent and a child relationship, allows for
reusability, extensibility.
• Additional code to an existing class without modifying it.
Uses keyword “extends”
• NUTSHELL: create a new class based on an existing class
with more data, create new objects based on this class
CREATING AND USING A CHILD CLASS
class Developer extends User {

public $skills = array();

public function getSalutation() {

return $this->title . " " . $this->name. ", Developer";

}

public function getSkillsString() {

echo implode(", ",$this->skills);

}

}
$developer = new Developer("Jane Smith", "Ms");

echo $developer;

echo "<br />";

$developer->skills = array("JavasScript", "HTML", "CSS");

$developer->skills[] = "PHP";

$developer->getSkillsString();
WHEN RUN, THE SCRIPT RETURNS:
Ms Jane Smith
JavasScript, HTML, CSS, PHP
FINISHED
QUESTION AND ANSWER TIME
THANK YOU FROM ALENA HOLLIGAN
Files at https://github.com/sketchings/oop-basics
Contact Info:
www.sketchings.com
@sketchings
alena@holligan.us
WELCOME TO ‘INTRO TO OOP WITH
PHP’ PART 2
Thank you for your interest. Files can be found at https://github.com/
sketchings/oop-basics
Contact Info:
www.sketchings.com
@sketchings
alena@holligan.us
INTRO TO OOP WITH PHP (PART 2)
A BASIC LOOK INTO OBJECT-ORIENTED PROGRAMMING
TERMINOLOGY
THE SINGLE MOST IMPORTANT PART
TERMS
• Class (properties, methods)
• Object
• Instance
• Abstraction
• Encapsulation
• Inheritance
TERMS CONTINUED
• Polymorphism
• Interface
• Abstract
• Type Hinting
• Namespaces
POLYMORPHISM
Polymorphism describes a pattern in object oriented programming in
which classes have different functionality while sharing a common
interface
INTERFACE
• Interface, specifies which methods a class must implement.
• All methods in interface must be public.
• Multiple interfaces can be implemented by using comma separation
• Interface may contain a CONSTANT, but may not be overridden by
implementing class
interface UserInterface {
public function getFormattedSalutation();
public function getName();
public function setName($name);
public function getTitle();
public function setTitle($title);
}
class User implements UserInterface { … }
ABSTRACT
An abstract class is a mix between an interface and a class. It can define
functionality as well as interface (in the form of abstract methods).
Classes extending an abstract class must implement all of the abstract
methods defined in the abstract class.
abstract class User { //class
public $name; //property
public getName() { //method
echo $this->name;
}
abstract public function setName($name);
}
class Developer extends User { … }
NAMESPACES
• Help create a new layer of code encapsulation
• Keep properties from colliding between areas of your code
• Only classes, interfaces, functions and constants are
affected
• Anything that does not have a namespace is considered in
the Global namespace (namespace = "")
NAMESPACES
• must be declared first (except 'declare)
• Can define multiple in the same file
• You can define that something be used in the "Global" namespace by
enclosing a non-labeled namespace in {} brackets.
• Use namespaces from within other namespaces, along with aliasing
• namespace myUser;
• class User { //class
• public $name; //property
• public getName() { //method
• echo $this->name;
• }
• public function setName($name);
• }
• class Developer extends myUserUser { … }
EXPLANATION COMPLETE
QUESTION AND ANSWER TIME
CHALLENGES
1. Change to User class to an abstract class.
2. Throw an error because your access is too restricted.
3. Extend the User class for another type of user, such as our
Developer example
4. Define 2 “User” classes in one file using namespacing
THANK YOU FROM ALENA HOLLIGAN
I hope you enjoyed this presentation and learned a lot in the
short time we had. Please stay tuned for more and fill out the
survey to help improve the training.
Contact Info:
www.sketchings.com
@sketchings
alena@holligan.us
RESOURCES
• LeanPub: The essentials of Object Oriented PHP

More Related Content

What's hot (20)

PDF
Demystifying Object-Oriented Programming - PHP[tek] 2017
Alena Holligan
 
PPTX
Intro to OOP PHP and Github
Jo Erik San Jose
 
PPT
Synapseindia object oriented programming in php
Synapseindiappsdevelopment
 
PPT
Introduction to OOP with PHP
Michael Peacock
 
PPT
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
PPT
Php Oop
mussawir20
 
PPTX
Ch8(oop)
Chhom Karath
 
PPTX
Oop in-php
Rajesh S
 
PDF
Object Oriented Programming with PHP 5 - More OOP
Wildan Maulana
 
PPT
Class 7 - PHP Object Oriented Programming
Ahmed Swilam
 
PPTX
FFW Gabrovo PMG - PHP OOP Part 3
Toni Kolev
 
PPT
Advanced php
hamfu
 
ZIP
Object Oriented PHP5
Jason Austin
 
PPTX
Anonymous Classes: Behind the Mask
Mark Baker
 
PPT
Class and Objects in PHP
Ramasubbu .P
 
PPTX
Oops in php
sanjay joshi
 
PPTX
Object oreinted php | OOPs
Ravi Bhadauria
 
PPT
Oops concepts in php
CPD INDIA
 
Demystifying Object-Oriented Programming - PHP[tek] 2017
Alena Holligan
 
Intro to OOP PHP and Github
Jo Erik San Jose
 
Synapseindia object oriented programming in php
Synapseindiappsdevelopment
 
Introduction to OOP with PHP
Michael Peacock
 
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
Php Oop
mussawir20
 
Ch8(oop)
Chhom Karath
 
Oop in-php
Rajesh S
 
Object Oriented Programming with PHP 5 - More OOP
Wildan Maulana
 
Class 7 - PHP Object Oriented Programming
Ahmed Swilam
 
FFW Gabrovo PMG - PHP OOP Part 3
Toni Kolev
 
Advanced php
hamfu
 
Object Oriented PHP5
Jason Austin
 
Anonymous Classes: Behind the Mask
Mark Baker
 
Class and Objects in PHP
Ramasubbu .P
 
Oops in php
sanjay joshi
 
Object oreinted php | OOPs
Ravi Bhadauria
 
Oops concepts in php
CPD INDIA
 

Similar to Demystifying Object-Oriented Programming #ssphp16 (20)

PDF
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Alena Holligan
 
PDF
Demystifying Object-Oriented Programming - ZendCon 2016
Alena Holligan
 
PDF
Demystifying Object-Oriented Programming - Lone Star PHP
Alena Holligan
 
PDF
Demystifying Object-Oriented Programming - Midwest PHP
Alena Holligan
 
PPTX
UNIT III (8).pptx
DrDhivyaaCRAssistant
 
PPTX
UNIT III (8).pptx
DrDhivyaaCRAssistant
 
PPTX
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
 
PDF
Demystifying Object-Oriented Programming #phpbnl18
Alena Holligan
 
PDF
OOP in PHP
Tarek Mahmud Apu
 
PDF
Object_oriented_programming_OOP_with_PHP.pdf
GammingWorld2
 
DOCX
Oops concept in php
selvabalaji k
 
PDF
tutorial54
tutorialsruby
 
PDF
tutorial54
tutorialsruby
 
PPTX
Php oop (1)
Sudip Simkhada
 
PPTX
OOP in PHP
Henry Osborne
 
PPTX
Lecture-10_PHP-OOP.pptx
ShaownRoy1
 
PDF
Demystifying oop
Alena Holligan
 
PDF
PHP OOP
Oscar Merida
 
PPT
OOP
thinkphp
 
PPTX
OOPS Characteristics (With Examples in PHP)
baabtra.com - No. 1 supplier of quality freshers
 
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Alena Holligan
 
Demystifying Object-Oriented Programming - ZendCon 2016
Alena Holligan
 
Demystifying Object-Oriented Programming - Lone Star PHP
Alena Holligan
 
Demystifying Object-Oriented Programming - Midwest PHP
Alena Holligan
 
UNIT III (8).pptx
DrDhivyaaCRAssistant
 
UNIT III (8).pptx
DrDhivyaaCRAssistant
 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
 
Demystifying Object-Oriented Programming #phpbnl18
Alena Holligan
 
OOP in PHP
Tarek Mahmud Apu
 
Object_oriented_programming_OOP_with_PHP.pdf
GammingWorld2
 
Oops concept in php
selvabalaji k
 
tutorial54
tutorialsruby
 
tutorial54
tutorialsruby
 
Php oop (1)
Sudip Simkhada
 
OOP in PHP
Henry Osborne
 
Lecture-10_PHP-OOP.pptx
ShaownRoy1
 
Demystifying oop
Alena Holligan
 
PHP OOP
Oscar Merida
 
OOPS Characteristics (With Examples in PHP)
baabtra.com - No. 1 supplier of quality freshers
 
Ad

More from Alena Holligan (20)

PDF
2023 Longhorn PHP - Learn to Succeed .pdf
Alena Holligan
 
PDF
Environmental variables
Alena Holligan
 
PDF
Dev parent
Alena Holligan
 
PDF
Dependency Injection
Alena Holligan
 
PDF
Dependency Management
Alena Holligan
 
PDF
Experiential Project Design
Alena Holligan
 
PDF
Reduce Reuse Refactor
Alena Holligan
 
PDF
Organization Patterns: MVC
Alena Holligan
 
PDF
When & Why: Interfaces, abstract classes, traits
Alena Holligan
 
PDF
Object Features
Alena Holligan
 
PDF
Obect-Oriented Collaboration
Alena Holligan
 
PDF
WordCamp Portland 2018: PHP for WordPress
Alena Holligan
 
PDF
Let's Talk Scope
Alena Holligan
 
PDF
Exploiting the Brain for Fun and Profit
Alena Holligan
 
PDF
Environmental Variables
Alena Holligan
 
PDF
Learn to succeed
Alena Holligan
 
PDF
Exploiting the Brain for Fun & Profit #zendcon2016
Alena Holligan
 
PDF
Presentation Bulgaria PHP
Alena Holligan
 
PDF
Presentation pnwphp
Alena Holligan
 
PDF
Exploiting the Brain for Fun and Profit - Lone Star 2016
Alena Holligan
 
2023 Longhorn PHP - Learn to Succeed .pdf
Alena Holligan
 
Environmental variables
Alena Holligan
 
Dev parent
Alena Holligan
 
Dependency Injection
Alena Holligan
 
Dependency Management
Alena Holligan
 
Experiential Project Design
Alena Holligan
 
Reduce Reuse Refactor
Alena Holligan
 
Organization Patterns: MVC
Alena Holligan
 
When & Why: Interfaces, abstract classes, traits
Alena Holligan
 
Object Features
Alena Holligan
 
Obect-Oriented Collaboration
Alena Holligan
 
WordCamp Portland 2018: PHP for WordPress
Alena Holligan
 
Let's Talk Scope
Alena Holligan
 
Exploiting the Brain for Fun and Profit
Alena Holligan
 
Environmental Variables
Alena Holligan
 
Learn to succeed
Alena Holligan
 
Exploiting the Brain for Fun & Profit #zendcon2016
Alena Holligan
 
Presentation Bulgaria PHP
Alena Holligan
 
Presentation pnwphp
Alena Holligan
 
Exploiting the Brain for Fun and Profit - Lone Star 2016
Alena Holligan
 
Ad

Recently uploaded (20)

PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PDF
Kubernetes - Architecture & Components.pdf
geethak285
 
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PDF
UiPath Agentic AI ile Akıllı Otomasyonun Yeni Çağı
UiPathCommunity
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PDF
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
PDF
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
PDF
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
Kubernetes - Architecture & Components.pdf
geethak285
 
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
UiPath Agentic AI ile Akıllı Otomasyonun Yeni Çağı
UiPathCommunity
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Practical Applications of AI in Local Government
OnBoard
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 

Demystifying Object-Oriented Programming #ssphp16

  • 1. WELCOME TO ‘INTRO TO OOP WITH PHP’ Thank you for your interest. Files can be found at https:// github.com/sketchings/oop-basics Contact Info: www.sketchings.com @sketchings [email protected]
  • 2. INTRO TO OOP WITH PHP (INTRODUCTION) A BASIC LOOK INTO OBJECT-ORIENTED PROGRAMMING
  • 3. WHAT IS OOP? ➔Object-Oriented Programing ➔A programming concept that treats functions and data as objects. ➔A programming methodology based on objects, instead of functions and procedures
  • 4. OOP VS PROCEDURAL OR FUNCTIONAL • OOP is built around the "nouns", the things in the system, and what they are capable of • Whereas procedural or functional programming is built around the "verbs" of the system, the things you want the system to do
  • 5. LET’S GET INTO SOME EXAMPLES Files can be found at https://github.com/ sketchings/oop-basics Contact Info: www.sketchings.com @sketchings [email protected]
  • 6. WELCOME TO ‘INTRO TO OOP WITH PHP’ PART 1 Thank you for your interest. Files can be found at https:// github.com/sketchings/oop-basics Contact Info: www.sketchings.com @sketchings [email protected]
  • 7. INTRO TO OOP WITH PHP (PART 1) A BASIC LOOK INTO OBJECT-ORIENTED PROGRAMMING
  • 9. TERMS • Class (properties, methods) • Object • Instance • Abstraction • Encapsulation • Inheritance
  • 10. CLASS • A template/blueprint that facilitates creation of objects. A set of program statements to do a certain task. Usually represents a noun, such as a person, place or thing. • Includes properties and methods — which are class functions
  • 11. OBJECT • Instance of a class. • In the real world object is a material thing that can be seen and touched. • In OOP, object is a self-contained entity that consists of both data and procedures.
  • 12. INSTANCE • Single occurrence/copy of an object • There might be one or several objects, but an instance is a specific copy, to which you can have a reference
  • 13. class User { //class private $name; //property public getName() { //method echo $this->name; } } $user1 = new User(); //first instance of object $user2 = new User(); //second instance of object
  • 14. ABSTRACTION • “An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of object and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer.”
 — G. Booch • This is the class architecture itself.
  • 15. ENCAPSULATION • Scope. Controls who can access what. Restricting access to some of the object’s components (properties and methods), preventing unauthorized access. • Public - everyone • Protected - inherited classes • Private - class itself, not children
  • 16. • class User {
 protected $name;
 protected $title;
 public function getFormattedSalutation() {
 return $this->getSalutation();
 }
 protected function getSalutation() {
 return $this->title . " " . $this->name;
 }
 public function getName() {
 return $this->name;
 }
 public function setName($name) {
 $this->name = $name;
 }
 public function getTitle() {
 return $this->title;
 }
 public function setTitle($title) {
 $this->title = $title;
 }
 }
  • 17. CREATING / USING THE OBJECT INSTANCE $user = new User();
 $user->setName("Jane Smith");
 $user->setTitle("Ms");
 echo $user->getFormattedSalutation(); When the script is run, it will return: Ms Jane Smith
  • 18. CONSTRUCTOR METHOD & MAGIC METHODS class User {
 protected $name;
 protected $title;
 
 public function __construct($name, $title) {
 $this->name = $name;
 $this->title = $title;
 }
 
 public function __toString() {
 return $this->getFormattedSalutation();
 }
 ...
 } For more see http://php.net/manual/en/language.oop5.magic.php
  • 19. CREATING / USING THE OBJECT INSTANCE $user = new User("Jane Smith","Ms");
 echo $user; When the script is run, it will return the same result as before: Ms Jane Smith
  • 20. INHERITANCE: PASSES KNOWLEDGE DOWN • Subclass, parent and a child relationship, allows for reusability, extensibility. • Additional code to an existing class without modifying it. Uses keyword “extends” • NUTSHELL: create a new class based on an existing class with more data, create new objects based on this class
  • 21. CREATING AND USING A CHILD CLASS class Developer extends User {
 public $skills = array();
 public function getSalutation() {
 return $this->title . " " . $this->name. ", Developer";
 }
 public function getSkillsString() {
 echo implode(", ",$this->skills);
 }
 } $developer = new Developer("Jane Smith", "Ms");
 echo $developer;
 echo "<br />";
 $developer->skills = array("JavasScript", "HTML", "CSS");
 $developer->skills[] = "PHP";
 $developer->getSkillsString();
  • 22. WHEN RUN, THE SCRIPT RETURNS: Ms Jane Smith JavasScript, HTML, CSS, PHP
  • 24. THANK YOU FROM ALENA HOLLIGAN Files at https://github.com/sketchings/oop-basics Contact Info: www.sketchings.com @sketchings [email protected]
  • 25. WELCOME TO ‘INTRO TO OOP WITH PHP’ PART 2 Thank you for your interest. Files can be found at https://github.com/ sketchings/oop-basics Contact Info: www.sketchings.com @sketchings [email protected]
  • 26. INTRO TO OOP WITH PHP (PART 2) A BASIC LOOK INTO OBJECT-ORIENTED PROGRAMMING
  • 27. TERMINOLOGY THE SINGLE MOST IMPORTANT PART
  • 28. TERMS • Class (properties, methods) • Object • Instance • Abstraction • Encapsulation • Inheritance
  • 29. TERMS CONTINUED • Polymorphism • Interface • Abstract • Type Hinting • Namespaces
  • 30. POLYMORPHISM Polymorphism describes a pattern in object oriented programming in which classes have different functionality while sharing a common interface
  • 31. INTERFACE • Interface, specifies which methods a class must implement. • All methods in interface must be public. • Multiple interfaces can be implemented by using comma separation • Interface may contain a CONSTANT, but may not be overridden by implementing class
  • 32. interface UserInterface { public function getFormattedSalutation(); public function getName(); public function setName($name); public function getTitle(); public function setTitle($title); } class User implements UserInterface { … }
  • 33. ABSTRACT An abstract class is a mix between an interface and a class. It can define functionality as well as interface (in the form of abstract methods). Classes extending an abstract class must implement all of the abstract methods defined in the abstract class.
  • 34. abstract class User { //class public $name; //property public getName() { //method echo $this->name; } abstract public function setName($name); } class Developer extends User { … }
  • 35. NAMESPACES • Help create a new layer of code encapsulation • Keep properties from colliding between areas of your code • Only classes, interfaces, functions and constants are affected • Anything that does not have a namespace is considered in the Global namespace (namespace = "")
  • 36. NAMESPACES • must be declared first (except 'declare) • Can define multiple in the same file • You can define that something be used in the "Global" namespace by enclosing a non-labeled namespace in {} brackets. • Use namespaces from within other namespaces, along with aliasing
  • 37. • namespace myUser; • class User { //class • public $name; //property • public getName() { //method • echo $this->name; • } • public function setName($name); • } • class Developer extends myUserUser { … }
  • 39. CHALLENGES 1. Change to User class to an abstract class. 2. Throw an error because your access is too restricted. 3. Extend the User class for another type of user, such as our Developer example 4. Define 2 “User” classes in one file using namespacing
  • 40. THANK YOU FROM ALENA HOLLIGAN I hope you enjoyed this presentation and learned a lot in the short time we had. Please stay tuned for more and fill out the survey to help improve the training. Contact Info: www.sketchings.com @sketchings [email protected]
  • 41. RESOURCES • LeanPub: The essentials of Object Oriented PHP