SlideShare a Scribd company logo
Demystifying

Object-Oriented Programming
Download Files: https://github.com/sketchings/oop-basics
Presented by: Alena Holligan
• Wife, and Mother of 3 young children
• PHP Teacher at Treehouse
• Portland PHP User Group Leader
www.sketchings.com

@sketchings

alena@holligan.us
Presented by: Alena Holligan
• Wife, and Mother of 3 young children
• PHP Teacher at Treehouse
• Portland PHP User Group Leader
www.sketchings.com

@sketchings

alena@holligan.us
PART 1: Terminology
Class (properties, methods, this)
Object
Instance
Abstraction
Encapsulation
PART 2: Polymorphism
Inheritance
Interface
Abstract Class
Traits
PART 3: Magic
Magic Methods
Magic Constants
Static Properties and Methods
Final
PART 4: Let’s Talk Scope
Magic Methods
Magic Constants
Static Properties and Methods
PART 1: Terminology
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

public $name; //property

public function getName() { //method

echo $this->name; //current object property

}

}
$user1 = new User(); //first instance of object
$user2 = new User(); //second instance of object
Abstraction
Managing the complexity of the system
Dealing with ideas rather than events
This is the class architecture itself.
Use something without knowing inner workings
Encapsulation
Binds together the data
and functions that
manipulate the data, and
keeps both safe from
outside interference and
misuse.
Properties
Methods
Team-up
OOP is great for working in groups
Team Challenges
Write a class with properties and methods
Example: User class with name, title, and salutation
PART 2:
Polymorphism
D-R-Y

Sharing Code
pol·y·mor·phism
/ˌpälēˈmôrfizəm/
The condition of occurring in several different forms
BIOLOGY
GENETICS
BIOCHEMISTRY
COMPUTING
Terms
Polymorphism
Inheritance
Interface
Abstract Class
Traits
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 a child class
class Developer extends User {

public $skills = array(); //additional property
public function getSkillsString(){ //additional method

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

}
public function getSalutation() {//override method

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

}

}
Using a child class
$developer = new Developer();

$developer->setName(”Jane Smith”);

$developer->setTitle(“Ms”);

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

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

echo $developer->getSkillsString();
When the script is run, it will return:
Ms Jane Smith, Developer
JavasScript, HTML, CSS, PHP
Team Challenges
Extend the User class for another type of user, such as our
Developer example
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 { … }
Team Challenges
Add an Interface for your Class
Abstract Class
An abstract class is a mix between an interface and a
class. It can define functionality as well as interface.
Classes extending an abstract class must implement all
of the abstract methods defined in the abstract class.
abstract class User { //abstract class
public $name; //class property
public getName() { //class method

echo $this->name;

}
abstract public function setName($name); //abstract method

}
class Developer extends User {

public setName($name) { //implementing the method

…
Team Challenges
Change to User class to an abstract class.
Try instantiating the User class
Traits
Composition
Horizontal Code Reuse
Multiple traits can be implemented
Creating Traits
trait Toolkit {

public $tools = array();

public function setTools($task) {

switch ($task) {

case “eat":

$this->tools = 

array("Spoon", "Fork", "Knife");

break;

...

}

}

public function showTools() {

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

}

}
Using Traits
class Developer extends User {

use Toolkit;

...

}
$developer = new Developer();

$developer->setTools("Eat");

echo $developer->showTools();
When run the script returns:
Spoon, Fork, Knife
When run, the script returns:
Ms Jane Smith
Spoon, Fork, Knife
Team Challenges
Add a trait to the User
PART 3: Magic
Magic Methods
Magic Constants
Magic Methods
Setup just like any other method
The Magic comes from the fact that they are
triggered and not called
For more see http://php.net/manual/en/
language.oop5.magic.php
Magic Constants
Predefined functions in PHP
For more see http://php.net/manual/en/
language.constants.predefined.php
Using Magic Methods and Constants
class User {
...



public function __construct($name, $title) {

$this->name = $name;

$this->title = $title;

}



public function __toString() {

return __CLASS__. “: “

. $this->getFormattedSalutation();

}

...

}
Creating / Using the Magic Method
$jane = new Developer(

"Jane Smith",

"Ms"

);

echo $jane;
When the script is run, it will return:
Developer: Ms Jane Smith
Challenges
Add a Magic Method
Add a Magic Constants
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
Keywords
Static
Final
Static Properties and Methods
abstract class User { //can be abstract or not

public static $encouragements = array(

“You are beautiful!”,

“You have this!”

);



public static function encourage()

{

$int = rand(0, count(self::$encouragements));

return self::$encouragements[$int];

}

...

}
Using the Static Method
echo User::encourage();
When the script is run, it will return:
You have this!
The FINAL Keyword
Prevents child classes from overriding a method by
prefixing the definition with final.
If the class itself is being defined final then it cannot
be extended.
class User { //can extend

final public getName() { //cannot extend

echo $this->name;

}
final class Developer extends User { //cannot extend

public getName() { //error

echo “My Name is: ” .$this->name;

}
class Manager extends Developer {…} //error
Team Challenges
Make sure you have a public, private and protected property or method
Add and use a Static Method
Define a parent method as FINAL and try to override in the child
Define a class as FINAL and try to create a child
Play with overriding properties and methods
LET’S TALK SCOPE
COMMUNICATION IN CODE
Function Scope
function functionScope(&$passed){ //can pass by reference
$myvar = 2;

$passed++;
echo 'INSIDE FUNCTION' . '<br />' . PHP_EOL;
echo 'Global $myvar: ' . $GLOBALS['myvar'] 

. '<br />' . PHP_EOL;

echo '$myvar: ' . $myvar . '<br />' . PHP_EOL;

echo '$passed: ' . $passed . '<br />' . PHP_EOL;
global $myvar;

$myvar++;

echo 'Global $myvar: ' . $myvar .'<br />'.PHP_EOL;
return $passed;

}
$myvar = 1;



echo 'GLOBAL before function'.'<br />'.PHP_EOL;

echo '$myvar: ' . $myvar . '<br />' . PHP_EOL;



$returned = functionScope($myvar);



echo 'GLOBAL after function' .'<br />'.PHP_EOL;

echo '$myvar: ' . $myvar . '<br />' . PHP_EOL;

echo '$passed: ' . $passed . '<br />' .PHP_EOL;

echo '$returned: ' .$returned.'<br />'.PHP_EOL;
When the script is run, it will return:
GLOBAL before function

$myvar: 1
INSIDE FUNCTION

Global $myvar: 2

$myvar: 2

$passed: 2

Global $myvar: 3
GLOBAL after function

$myvar: 3

$passed: //error because we’re no longer in function

$returned: 3
Class & Method Scope
abstract class AbstractScope {

const CLASS_CONSTANT = 'abstract constant';

public $myvar = 101;

}
class ClassScopeA extends AbstractScope {

const CLASS_CONSTANT = 'class constant';

public $myvar = 100;

public static $staticvar = 200;

private $privatevar = 300;
public function displayProperties() {

echo parent::CLASS_CONSTANT . '<br />' . PHP_EOL;

echo self::CLASS_CONSTANT . '<br />' . PHP_EOL;

echo '$this->privatevar: '.$this->privatevar.'<br />'.PHP_EOL;

}

}
class ClassScopeB extends ClassScopeA {

public $myvar = 1000;

public static $staticvar = 2000;

private $privatevar = 3000;

}
echo "STATIC CALL ClassScopeA" . '<br />' . PHP_EOL;

echo ‘ClassScopeA $staticvar: ' 

. ClassScopeA::$staticvar . '<br />' . PHP_EOL;
$classA = new ClassScopeA();

echo "FROM classA Object" . '<br />' . PHP_EOL;

var_dump($classA);

$classA->displayProperties();
echo "FROM classB Object" . '<br />' . PHP_EOL;

$classB = new ClassScopeB();

var_dump($classB);

$classB->displayProperties();
STATIC CALL ClassScopeA

ClassScopeA $staticvar: 200
FROM classA Object

object(ClassScopeA)[1]

public 'myvar' => int 100

private 'privatevar' => int 300

abstract class constant

class constant

$this->privatevar: 300
FROM classB Object

object(ClassScopeB)[2]

public 'myvar' => int 1000

private 'privatevar' => int 3000

private 'privatevar' (ClassScopeA) => int 300

abstract class constant

class constant

$this->privatevar: 300
Package Scope
“MOM!”
“MOM!”
Application Scope
Demystifying Object-Oriented Programming #phpbnl18
Namespacing
namespace sketchingsoop;
//reference the global namespace

class NamespaceScopeA extends ClassScopeA {

public $myvar = 1.1;

private $privatevar = 1.2;

}
//reference the current namespace 

class NamespaceScopeB extends NamespaceScopeA {

public $myvar = 402;

private $privatevar = 502;

}
use sketchingsoopNamespaceScopeB as blah;
$classA = new sketchingsoopNamespaceScopeA();

echo "FROM NamespaceScopeA Object".'<br />'.PHP_EOL;

var_dump($classA);

$classA->displayProperties();
$classB = new blah();

echo "FROM NamespaceScopeB Object".'<br />'.PHP_EOL;

var_dump($classB);

$classB->displayProperties();
FROM NamespaceScopeA Object
object(sketchingsoopNamespaceScopeA)[1]

public 'myvar' => float 1.1

private 'privatevar' => float 1.2

private 'privatevar' (ClassScopeA) => int 300
abstract class constant

class constant

$this->privatevar: 300
FROM NamespaceScopeB Object
object(sketchingsoopNamespaceScopeB)[2]

public 'myvar' => int 402

private 'privatevar' => int 502

private 'privatevar' (sketchingsoopNamespaceScopeA) => float 1.2

private 'privatevar' (ClassScopeA) => int 300
abstract class constant

class constant

$this->privatevar: 300
Resources
LeanPub: The Essentials of Object Oriented PHP
Head First Object-Oriented Analysis and Design
Presented by: Alena Holligan
• Wife and Mother of 3 young children
• PHP Teacher at Treehouse
• Portland PHP User Group Leader
www.sketchings.com

@sketchings

alena@holligan.us
Download Files: https://github.com/sketchings/oop-basics
https://joind.in/talk/1b272

More Related Content

What's hot (20)

Class and Objects in PHP
Class and Objects in PHPClass and Objects in PHP
Class and Objects in PHP
Ramasubbu .P
 
Php Oop
Php OopPhp Oop
Php Oop
mussawir20
 
PHP Classes and OOPS Concept
PHP Classes and OOPS ConceptPHP Classes and OOPS Concept
PHP Classes and OOPS Concept
Dot Com Infoway - Custom Software, Mobile, Web Application Development and Digital Marketing Company
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
Alena Holligan
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
Ahmed Swilam
 
Oops in PHP
Oops in PHPOops in PHP
Oops in PHP
Mindfire Solutions
 
Oop in-php
Oop in-phpOop in-php
Oop in-php
Rajesh S
 
Inheritance
InheritanceInheritance
Inheritance
SangeethaSasi1
 
Take the Plunge with OOP from #pnwphp
Take the Plunge with OOP from #pnwphpTake the Plunge with OOP from #pnwphp
Take the Plunge with OOP from #pnwphp
Alena Holligan
 
PHP OOP
PHP OOPPHP OOP
PHP OOP
Oscar Merida
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
Chhom Karath
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5
Jason Austin
 
Object oriented programming in php 5
Object oriented programming in php 5Object oriented programming in php 5
Object oriented programming in php 5
Sayed Ahmed
 
A Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpA Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented Php
Michael Girouard
 
Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPs
Ravi Bhadauria
 
PHP- Introduction to Object Oriented PHP
PHP-  Introduction to Object Oriented PHPPHP-  Introduction to Object Oriented PHP
PHP- Introduction to Object Oriented PHP
Vibrant Technologies & Computers
 
Oops in php
Oops in phpOops in php
Oops in php
sanjay joshi
 
Php object orientation and classes
Php object orientation and classesPhp object orientation and classes
Php object orientation and classes
Kumar
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHP
Michael Peacock
 
Dr. Rajeshree Khande : Java Inheritance
Dr. Rajeshree Khande : Java InheritanceDr. Rajeshree Khande : Java Inheritance
Dr. Rajeshree Khande : Java Inheritance
jalinder123
 

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

Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016
Alena Holligan
 
Demystifying Object-Oriented Programming #ssphp16
Demystifying Object-Oriented Programming #ssphp16Demystifying Object-Oriented Programming #ssphp16
Demystifying Object-Oriented Programming #ssphp16
Alena Holligan
 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
 
UNIT III (8).pptx
UNIT III (8).pptxUNIT III (8).pptx
UNIT III (8).pptx
DrDhivyaaCRAssistant
 
UNIT III (8).pptx
UNIT III (8).pptxUNIT III (8).pptx
UNIT III (8).pptx
DrDhivyaaCRAssistant
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
Tarek Mahmud Apu
 
PHP OOP Lecture - 04.pptx
PHP OOP Lecture - 04.pptxPHP OOP Lecture - 04.pptx
PHP OOP Lecture - 04.pptx
Atikur Rahman
 
Object Oriented Programming in PHP
Object Oriented Programming  in PHPObject Oriented Programming  in PHP
Object Oriented Programming in PHP
wahidullah mudaser
 
Let's Talk Scope
Let's Talk ScopeLet's Talk Scope
Let's Talk Scope
Alena Holligan
 
Obect-Oriented Collaboration
Obect-Oriented CollaborationObect-Oriented Collaboration
Obect-Oriented Collaboration
Alena Holligan
 
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
c91632a4-2e92-4edf-b750-358da15ed1b1.pptxc91632a4-2e92-4edf-b750-358da15ed1b1.pptx
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
ajayparmeshwarmahaja
 
Lecture 17 - PHP-Object-Orientation.pptx
Lecture 17 - PHP-Object-Orientation.pptxLecture 17 - PHP-Object-Orientation.pptx
Lecture 17 - PHP-Object-Orientation.pptx
DavidLazar17
 
Objects, Testing, and Responsibility
Objects, Testing, and ResponsibilityObjects, Testing, and Responsibility
Objects, Testing, and Responsibility
machuga
 
Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016
Chris Tankersley
 
Intro to OOP PHP and Github
Intro to OOP PHP and GithubIntro to OOP PHP and Github
Intro to OOP PHP and Github
Jo Erik San Jose
 
PHP-05-Objects.ppt
PHP-05-Objects.pptPHP-05-Objects.ppt
PHP-05-Objects.ppt
rani marri
 
Object oriented programming in php
Object oriented programming in phpObject oriented programming in php
Object oriented programming in php
Aashiq Kuchey
 
FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3
Toni Kolev
 
Advanced php
Advanced phpAdvanced php
Advanced php
hamfu
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
ShaownRoy1
 
Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016
Alena Holligan
 
Demystifying Object-Oriented Programming #ssphp16
Demystifying Object-Oriented Programming #ssphp16Demystifying Object-Oriented Programming #ssphp16
Demystifying Object-Oriented Programming #ssphp16
Alena Holligan
 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
 
PHP OOP Lecture - 04.pptx
PHP OOP Lecture - 04.pptxPHP OOP Lecture - 04.pptx
PHP OOP Lecture - 04.pptx
Atikur Rahman
 
Object Oriented Programming in PHP
Object Oriented Programming  in PHPObject Oriented Programming  in PHP
Object Oriented Programming in PHP
wahidullah mudaser
 
Obect-Oriented Collaboration
Obect-Oriented CollaborationObect-Oriented Collaboration
Obect-Oriented Collaboration
Alena Holligan
 
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
c91632a4-2e92-4edf-b750-358da15ed1b1.pptxc91632a4-2e92-4edf-b750-358da15ed1b1.pptx
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
ajayparmeshwarmahaja
 
Lecture 17 - PHP-Object-Orientation.pptx
Lecture 17 - PHP-Object-Orientation.pptxLecture 17 - PHP-Object-Orientation.pptx
Lecture 17 - PHP-Object-Orientation.pptx
DavidLazar17
 
Objects, Testing, and Responsibility
Objects, Testing, and ResponsibilityObjects, Testing, and Responsibility
Objects, Testing, and Responsibility
machuga
 
Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016
Chris Tankersley
 
Intro to OOP PHP and Github
Intro to OOP PHP and GithubIntro to OOP PHP and Github
Intro to OOP PHP and Github
Jo Erik San Jose
 
PHP-05-Objects.ppt
PHP-05-Objects.pptPHP-05-Objects.ppt
PHP-05-Objects.ppt
rani marri
 
Object oriented programming in php
Object oriented programming in phpObject oriented programming in php
Object oriented programming in php
Aashiq Kuchey
 
FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3
Toni Kolev
 
Advanced php
Advanced phpAdvanced php
Advanced php
hamfu
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
ShaownRoy1
 
Ad

More from Alena Holligan (20)

2023 Longhorn PHP - Learn to Succeed .pdf
2023 Longhorn PHP - Learn to Succeed .pdf2023 Longhorn PHP - Learn to Succeed .pdf
2023 Longhorn PHP - Learn to Succeed .pdf
Alena Holligan
 
Environmental variables
Environmental variablesEnvironmental variables
Environmental variables
Alena Holligan
 
Dev parent
Dev parentDev parent
Dev parent
Alena Holligan
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
Alena Holligan
 
Dependency Management
Dependency ManagementDependency Management
Dependency Management
Alena Holligan
 
Experiential Project Design
Experiential Project DesignExperiential Project Design
Experiential Project Design
Alena Holligan
 
Reduce Reuse Refactor
Reduce Reuse RefactorReduce Reuse Refactor
Reduce Reuse Refactor
Alena Holligan
 
Organization Patterns: MVC
Organization Patterns: MVCOrganization Patterns: MVC
Organization Patterns: MVC
Alena Holligan
 
When & Why: Interfaces, abstract classes, traits
When & Why: Interfaces, abstract classes, traitsWhen & Why: Interfaces, abstract classes, traits
When & Why: Interfaces, abstract classes, traits
Alena Holligan
 
Object Features
Object FeaturesObject Features
Object Features
Alena Holligan
 
WordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressWordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPress
Alena Holligan
 
Exploiting the Brain for Fun and Profit
Exploiting the Brain for Fun and ProfitExploiting the Brain for Fun and Profit
Exploiting the Brain for Fun and Profit
Alena Holligan
 
Environmental Variables
Environmental VariablesEnvironmental Variables
Environmental Variables
Alena Holligan
 
Learn to succeed
Learn to succeedLearn to succeed
Learn to succeed
Alena Holligan
 
Exploiting the Brain for Fun & Profit #zendcon2016
Exploiting the Brain for Fun & Profit #zendcon2016Exploiting the Brain for Fun & Profit #zendcon2016
Exploiting the Brain for Fun & Profit #zendcon2016
Alena Holligan
 
Presentation Bulgaria PHP
Presentation Bulgaria PHPPresentation Bulgaria PHP
Presentation Bulgaria PHP
Alena Holligan
 
Presentation pnwphp
Presentation pnwphpPresentation pnwphp
Presentation pnwphp
Alena Holligan
 
Exploiting the Brain for Fun and Profit - Lone Star 2016
Exploiting the Brain for Fun and Profit - Lone Star 2016Exploiting the Brain for Fun and Profit - Lone Star 2016
Exploiting the Brain for Fun and Profit - Lone Star 2016
Alena Holligan
 
Exploiting the Brain for Fun & Profit #ssphp16
Exploiting the Brain for Fun & Profit #ssphp16Exploiting the Brain for Fun & Profit #ssphp16
Exploiting the Brain for Fun & Profit #ssphp16
Alena Holligan
 
Exploiting the Brain for Fun & Profit #dc4d 2016
Exploiting the Brain for Fun & Profit #dc4d 2016Exploiting the Brain for Fun & Profit #dc4d 2016
Exploiting the Brain for Fun & Profit #dc4d 2016
Alena Holligan
 
2023 Longhorn PHP - Learn to Succeed .pdf
2023 Longhorn PHP - Learn to Succeed .pdf2023 Longhorn PHP - Learn to Succeed .pdf
2023 Longhorn PHP - Learn to Succeed .pdf
Alena Holligan
 
Environmental variables
Environmental variablesEnvironmental variables
Environmental variables
Alena Holligan
 
Experiential Project Design
Experiential Project DesignExperiential Project Design
Experiential Project Design
Alena Holligan
 
Organization Patterns: MVC
Organization Patterns: MVCOrganization Patterns: MVC
Organization Patterns: MVC
Alena Holligan
 
When & Why: Interfaces, abstract classes, traits
When & Why: Interfaces, abstract classes, traitsWhen & Why: Interfaces, abstract classes, traits
When & Why: Interfaces, abstract classes, traits
Alena Holligan
 
WordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressWordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPress
Alena Holligan
 
Exploiting the Brain for Fun and Profit
Exploiting the Brain for Fun and ProfitExploiting the Brain for Fun and Profit
Exploiting the Brain for Fun and Profit
Alena Holligan
 
Environmental Variables
Environmental VariablesEnvironmental Variables
Environmental Variables
Alena Holligan
 
Exploiting the Brain for Fun & Profit #zendcon2016
Exploiting the Brain for Fun & Profit #zendcon2016Exploiting the Brain for Fun & Profit #zendcon2016
Exploiting the Brain for Fun & Profit #zendcon2016
Alena Holligan
 
Presentation Bulgaria PHP
Presentation Bulgaria PHPPresentation Bulgaria PHP
Presentation Bulgaria PHP
Alena Holligan
 
Exploiting the Brain for Fun and Profit - Lone Star 2016
Exploiting the Brain for Fun and Profit - Lone Star 2016Exploiting the Brain for Fun and Profit - Lone Star 2016
Exploiting the Brain for Fun and Profit - Lone Star 2016
Alena Holligan
 
Exploiting the Brain for Fun & Profit #ssphp16
Exploiting the Brain for Fun & Profit #ssphp16Exploiting the Brain for Fun & Profit #ssphp16
Exploiting the Brain for Fun & Profit #ssphp16
Alena Holligan
 
Exploiting the Brain for Fun & Profit #dc4d 2016
Exploiting the Brain for Fun & Profit #dc4d 2016Exploiting the Brain for Fun & Profit #dc4d 2016
Exploiting the Brain for Fun & Profit #dc4d 2016
Alena Holligan
 
Ad

Recently uploaded (20)

Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Domino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use CasesDomino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use Cases
panagenda
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
How to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptxHow to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Domino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use CasesDomino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use Cases
panagenda
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
How to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptxHow to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 

Demystifying Object-Oriented Programming #phpbnl18

  • 1. Demystifying
 Object-Oriented Programming Download Files: https://github.com/sketchings/oop-basics Presented by: Alena Holligan • Wife, and Mother of 3 young children • PHP Teacher at Treehouse • Portland PHP User Group Leader www.sketchings.com
 @sketchings
 [email protected]
  • 2. Presented by: Alena Holligan • Wife, and Mother of 3 young children • PHP Teacher at Treehouse • Portland PHP User Group Leader www.sketchings.com
 @sketchings
 [email protected]
  • 3. PART 1: Terminology Class (properties, methods, this) Object Instance Abstraction Encapsulation
  • 5. PART 3: Magic Magic Methods Magic Constants Static Properties and Methods Final
  • 6. PART 4: Let’s Talk Scope Magic Methods Magic Constants Static Properties and Methods
  • 8. 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
  • 9. 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.
  • 10. 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
  • 11. class User { //class
 public $name; //property
 public function getName() { //method
 echo $this->name; //current object property
 }
 } $user1 = new User(); //first instance of object $user2 = new User(); //second instance of object
  • 12. Abstraction Managing the complexity of the system Dealing with ideas rather than events This is the class architecture itself. Use something without knowing inner workings
  • 13. Encapsulation Binds together the data and functions that manipulate the data, and keeps both safe from outside interference and misuse. Properties Methods
  • 14. Team-up OOP is great for working in groups
  • 15. Team Challenges Write a class with properties and methods Example: User class with name, title, and salutation
  • 17. pol·y·mor·phism /ˌpälēˈmôrfizəm/ The condition of occurring in several different forms BIOLOGY GENETICS BIOCHEMISTRY COMPUTING
  • 19. 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
  • 20. Creating a child class class Developer extends User {
 public $skills = array(); //additional property public function getSkillsString(){ //additional method
 return implode(", ",$this->skills);
 } public function getSalutation() {//override method
 return $this->title . " " . $this->name. ", Developer";
 }
 }
  • 21. Using a child class $developer = new Developer();
 $developer->setName(”Jane Smith”);
 $developer->setTitle(“Ms”);
 echo $developer->getFormatedSalutation(); $developer->skills = array("JavasScript", "HTML", "CSS");
 $developer->skills[] = “PHP";
 echo $developer->getSkillsString(); When the script is run, it will return: Ms Jane Smith, Developer JavasScript, HTML, CSS, PHP
  • 22. Team Challenges Extend the User class for another type of user, such as our Developer example
  • 23. 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
  • 24. interface UserInterface { public function getFormattedSalutation(); public function getName(); public function setName($name); public function getTitle(); public function setTitle($title); } class User implements UserInterface { … }
  • 25. Team Challenges Add an Interface for your Class
  • 26. Abstract Class An abstract class is a mix between an interface and a class. It can define functionality as well as interface. Classes extending an abstract class must implement all of the abstract methods defined in the abstract class.
  • 27. abstract class User { //abstract class public $name; //class property public getName() { //class method
 echo $this->name;
 } abstract public function setName($name); //abstract method
 } class Developer extends User {
 public setName($name) { //implementing the method
 …
  • 28. Team Challenges Change to User class to an abstract class. Try instantiating the User class
  • 30. Creating Traits trait Toolkit {
 public $tools = array();
 public function setTools($task) {
 switch ($task) {
 case “eat":
 $this->tools = 
 array("Spoon", "Fork", "Knife");
 break;
 ...
 }
 }
 public function showTools() {
 return implode(", ",$this->skills);
 }
 }
  • 31. Using Traits class Developer extends User {
 use Toolkit;
 ...
 } $developer = new Developer();
 $developer->setTools("Eat");
 echo $developer->showTools(); When run the script returns: Spoon, Fork, Knife
  • 32. When run, the script returns: Ms Jane Smith Spoon, Fork, Knife
  • 33. Team Challenges Add a trait to the User
  • 34. PART 3: Magic Magic Methods Magic Constants
  • 35. Magic Methods Setup just like any other method The Magic comes from the fact that they are triggered and not called For more see http://php.net/manual/en/ language.oop5.magic.php
  • 36. Magic Constants Predefined functions in PHP For more see http://php.net/manual/en/ language.constants.predefined.php
  • 37. Using Magic Methods and Constants class User { ...
 
 public function __construct($name, $title) {
 $this->name = $name;
 $this->title = $title;
 }
 
 public function __toString() {
 return __CLASS__. “: “
 . $this->getFormattedSalutation();
 }
 ...
 }
  • 38. Creating / Using the Magic Method $jane = new Developer(
 "Jane Smith",
 "Ms"
 );
 echo $jane; When the script is run, it will return: Developer: Ms Jane Smith
  • 39. Challenges Add a Magic Method Add a Magic Constants
  • 40. 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
  • 42. Static Properties and Methods abstract class User { //can be abstract or not
 public static $encouragements = array(
 “You are beautiful!”,
 “You have this!”
 );
 
 public static function encourage()
 {
 $int = rand(0, count(self::$encouragements));
 return self::$encouragements[$int];
 }
 ...
 }
  • 43. Using the Static Method echo User::encourage(); When the script is run, it will return: You have this!
  • 44. The FINAL Keyword Prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.
  • 45. class User { //can extend
 final public getName() { //cannot extend
 echo $this->name;
 } final class Developer extends User { //cannot extend
 public getName() { //error
 echo “My Name is: ” .$this->name;
 } class Manager extends Developer {…} //error
  • 46. Team Challenges Make sure you have a public, private and protected property or method Add and use a Static Method Define a parent method as FINAL and try to override in the child Define a class as FINAL and try to create a child Play with overriding properties and methods
  • 49. function functionScope(&$passed){ //can pass by reference $myvar = 2;
 $passed++; echo 'INSIDE FUNCTION' . '<br />' . PHP_EOL; echo 'Global $myvar: ' . $GLOBALS['myvar'] 
 . '<br />' . PHP_EOL;
 echo '$myvar: ' . $myvar . '<br />' . PHP_EOL;
 echo '$passed: ' . $passed . '<br />' . PHP_EOL; global $myvar;
 $myvar++;
 echo 'Global $myvar: ' . $myvar .'<br />'.PHP_EOL; return $passed;
 }
  • 50. $myvar = 1;
 
 echo 'GLOBAL before function'.'<br />'.PHP_EOL;
 echo '$myvar: ' . $myvar . '<br />' . PHP_EOL;
 
 $returned = functionScope($myvar);
 
 echo 'GLOBAL after function' .'<br />'.PHP_EOL;
 echo '$myvar: ' . $myvar . '<br />' . PHP_EOL;
 echo '$passed: ' . $passed . '<br />' .PHP_EOL;
 echo '$returned: ' .$returned.'<br />'.PHP_EOL;
  • 51. When the script is run, it will return: GLOBAL before function
 $myvar: 1 INSIDE FUNCTION
 Global $myvar: 2
 $myvar: 2
 $passed: 2
 Global $myvar: 3 GLOBAL after function
 $myvar: 3
 $passed: //error because we’re no longer in function
 $returned: 3
  • 52. Class & Method Scope
  • 53. abstract class AbstractScope {
 const CLASS_CONSTANT = 'abstract constant';
 public $myvar = 101;
 } class ClassScopeA extends AbstractScope {
 const CLASS_CONSTANT = 'class constant';
 public $myvar = 100;
 public static $staticvar = 200;
 private $privatevar = 300; public function displayProperties() {
 echo parent::CLASS_CONSTANT . '<br />' . PHP_EOL;
 echo self::CLASS_CONSTANT . '<br />' . PHP_EOL;
 echo '$this->privatevar: '.$this->privatevar.'<br />'.PHP_EOL;
 }
 } class ClassScopeB extends ClassScopeA {
 public $myvar = 1000;
 public static $staticvar = 2000;
 private $privatevar = 3000;
 }
  • 54. echo "STATIC CALL ClassScopeA" . '<br />' . PHP_EOL;
 echo ‘ClassScopeA $staticvar: ' 
 . ClassScopeA::$staticvar . '<br />' . PHP_EOL; $classA = new ClassScopeA();
 echo "FROM classA Object" . '<br />' . PHP_EOL;
 var_dump($classA);
 $classA->displayProperties(); echo "FROM classB Object" . '<br />' . PHP_EOL;
 $classB = new ClassScopeB();
 var_dump($classB);
 $classB->displayProperties();
  • 55. STATIC CALL ClassScopeA
 ClassScopeA $staticvar: 200 FROM classA Object
 object(ClassScopeA)[1]
 public 'myvar' => int 100
 private 'privatevar' => int 300
 abstract class constant
 class constant
 $this->privatevar: 300 FROM classB Object
 object(ClassScopeB)[2]
 public 'myvar' => int 1000
 private 'privatevar' => int 3000
 private 'privatevar' (ClassScopeA) => int 300
 abstract class constant
 class constant
 $this->privatevar: 300
  • 61. Namespacing namespace sketchingsoop; //reference the global namespace
 class NamespaceScopeA extends ClassScopeA {
 public $myvar = 1.1;
 private $privatevar = 1.2;
 } //reference the current namespace 
 class NamespaceScopeB extends NamespaceScopeA {
 public $myvar = 402;
 private $privatevar = 502;
 }
  • 62. use sketchingsoopNamespaceScopeB as blah; $classA = new sketchingsoopNamespaceScopeA();
 echo "FROM NamespaceScopeA Object".'<br />'.PHP_EOL;
 var_dump($classA);
 $classA->displayProperties(); $classB = new blah();
 echo "FROM NamespaceScopeB Object".'<br />'.PHP_EOL;
 var_dump($classB);
 $classB->displayProperties();
  • 63. FROM NamespaceScopeA Object object(sketchingsoopNamespaceScopeA)[1]
 public 'myvar' => float 1.1
 private 'privatevar' => float 1.2
 private 'privatevar' (ClassScopeA) => int 300 abstract class constant
 class constant
 $this->privatevar: 300 FROM NamespaceScopeB Object object(sketchingsoopNamespaceScopeB)[2]
 public 'myvar' => int 402
 private 'privatevar' => int 502
 private 'privatevar' (sketchingsoopNamespaceScopeA) => float 1.2
 private 'privatevar' (ClassScopeA) => int 300 abstract class constant
 class constant
 $this->privatevar: 300
  • 64. Resources LeanPub: The Essentials of Object Oriented PHP Head First Object-Oriented Analysis and Design
  • 65. Presented by: Alena Holligan • Wife and Mother of 3 young children • PHP Teacher at Treehouse • Portland PHP User Group Leader www.sketchings.com
 @sketchings
 [email protected] Download Files: https://github.com/sketchings/oop-basics https://joind.in/talk/1b272