SlideShare a Scribd company logo
PHP-  Introduction to Object Oriented PHP
Introduction to Object-
Oriented PHP
2
• Topics:
o OOP concepts – overview, throughout the chapter
o Defining and using objects
• Defining and instantiating classes
• Defining and using variables, constants, and operations
• Getters and setters
o Defining and using inheritance and polymorphism
• Building subclasses and overriding operations
• Using interfaces
o Advanced object-oriented functionality in PHP
• Comparing objects, Printing objects,
• Type hinting, Cloning objects,
• Overloading methods, (some sections WILL NOT BE
COVERED!!!)
3
Developing Object-Oriented PHP
• Object-oriented programming (OOP) refers to the creation of reusable
software object-types / classes that can be efficiently developed and
easily incorporated into multiple programs.
• In OOP an object represents an entity in the real world (a student, a desk,
a button, a file, a text input area, a loan, a web page, a shopping cart).
• An OOP program = a collection of objects that interact to solve a task /
problem.
4
Object-Oriented Programming
• Objects are self-contained, with data and operations that pertain to them
assembled into a single entity.
o In procedural programming data and operations are separate → this
methodology requires sending data to methods!
• Objects have:
o Identity; ex: 2 “OK” buttons, same attributes → separate handle vars
o State → a set of attributes (aka member variables, properties, data
fields) = properties or variables that relate to / describe the object, with
their current values.
o Behavior → a set of operations (aka methods) = actions or functions
that the object can perform to modify itself – its state, or perform for
some external effect / result.
5
Object-Oriented Programming
• Encapsulation (aka data hiding) central in OOP
o = access to data within an object is available only via the object’s
operations (= known as the interface of the object)
o = internal aspects of objects are hidden, wrapped as a birthday
present is wrapped by colorful paper 
• Advantages:
o objects can be used as black-boxes, if their interface is known;
o implementation of an interface can be changed without a cascading
effect to other parts of the project → if the interface doesn’t change
6
Object-Oriented Programming
• Classes are constructs that define objects of the same type.
A class is a template or blueprint that defines what an object’s data and
methods will be.
Objects of a class have:
o Same operations, behaving the same way
o Same attributes representing the same features, but values of those
attributes (= state) can vary from object to object
• An object is an instance of a class.
(terms objects and instances are used interchangeably)
• Any number of instances of a class can be created.
7
Object-Oriented Programming
• Small Web projects
o Consist of web scripts designed and written using an ad-hoc approach; a
function-oriented, procedural methodology
• Large Web software projects
o Need a properly thought-out development methodology – OOP →
o OO approach can help manage project complexity, increase code
reusability, reduce costs.
o OO analysis and design process = decide what object types, what hidden
data/operations and wrapper operations for each object type
o UML – as tool in OO design, to allow to describe classes and class
relationships
8
OOP in Web Programming
• A minimal class definition:
class classname { // classname is a PHP identifier!
// the class body = data & function member definitions
}
• Attributes
o are declared as variables within the class definition using keywords that
match their visibility: public, private, or protected.
(Recall that PHP doesn't otherwise have declarations of variables →
data member declarations against the nature of PHP?)
• Operations
o are created by declaring functions within the class definition.
9
Creating Classes in PHP
• Constructor = function used to create an object of the
class
o Declared as a function with a special name:
function __construct (param_list) { … }
o Usually performs initialization tasks: e.g. sets attributes to appropriate
starting values
o Called automatically when an object is created
o A default no-argument constructor is provided by the compiler only if a
constructor function is not explicitly declared in the class
o Cannot be overloaded (= 2+ constructors for a class); if you need a
variable # of parameters, use flexible parameter lists…
10
Creating Classes in PHP
• Destructor = opposite of constructor
o Declared as a function with a special name, cannot take parameters
function __destruct () { … }
o Allows some functionality that will be automatically executed just before
an object is destroyed
 An object is removed when there is no reference variable/handle left
to it
 Usually during the "script shutdown phase", which is typically right
before the execution of the PHP script finishes
o A default destructor provided by the compiler only if a destructor
function is not explicitly declared in the class
11
Creating Classes in PHP
• Create an object of a class = a particular individual that is a member of the
class by using the new keyword:
$newClassVariable = new ClassName(actual_param_list);
• Notes:
o Scope for PHP classes is global (program script level), as it is for functions
o Class names are case insensitive as are functions
o PHP 5 allows you to define multiple classes in a single program script
o The PHP parser reads classes into memory immediately after functions ⇒
class construction does not fail because a class is not previously defined in
the program scope.
12
Instantiating Classes
• From operations within the class, class’s data / methods can be
accessed / called by using:
o $this = a variable that refers to the current instance of the class,
and can be used only in the definition of the class, including the
constructor & destructor
o The pointer operator -> (similar to Java’s object member access operator
“.” )
o class Test {
public $attribute;
function f ($val) {
$this -> attribute = $val; // $this is mandatory!
} // if omitted, $attribute is
treated
} // as a local var in the function
13
Using Data/Method Members
No $ sign here
• From outside the class, accessible (as determined by access modifiers) data
and methods are accessed through a variable holding an instance of the
class, by using the same pointer operator.
class Test {
public $attribute;
}
$t = new Test();
$t->attribute = “value”;
echo $t->attribute;
14
Using Data/Method Members
• Three access / visibility modifiers introduced in PHP 5, which affect the scope
of access to class variables and functions:
o public : public class variables and functions can be accessed from inside
and outside the class
o protected : hides a variable or function from direct external class access
+ protected members are available in subclasses
o private : hides a variable or function from direct external class access +
protected members are hidden (NOT available) from all subclasses
• An access modifier has to be provided for each class instance variable
• Static class variables and functions can be declared without an access
modifier → default is public
15
Defining and Using Variables, Constants
and Functions
• Encapsulation : hide attributes from direct access from outside a class and
provide controlled access through accessor and mutator functions
o You can write custom getVariable() / setVariable($var) functions or
o Overload the functionality with the __get() and __set() functions in PHP
• __get() and __set()
o Prototype:
mixed __get($var);
// param represents the name of an attribute, __get returns the value of
that attribute
void __set($var, $value);
// params are the name of an attribute and the value to set it to
16
Getters and Setters
• __get() and __set()
o Can only be used for non-static attributes!
o You do not directly call these functions;
For an instance $acc of the BankAccount class:
$acc->Balance = 1000;
implicitly calls the __set() function with the value of
$name set to ‘Balance’, and the value of $value set to
1000.
(__get() works in a similar way)
17
Getters and Setters
• __get() and __set() functions’ value: a single access
point to an attribute ensures complete control over:
o attribute’s values
function __set($name, $value) {
echo "<p>Setter for $name called!</p>";
if (strcasecmp($name, "Balance")==0 && ($value>=0))
$this->$name = $value;
...
}
o underlying implementation: as a variable, retrieved from a
db when needed, a value inferred based on the values of
other attributes
→ transparent for clients as long as the accessor / mutator18
Getters and Setters
• Classes in Web development:
o Pages
o User-interface components
o Shopping carts
o Product categories
o Customers
• TLA Consulting example revisited - a Page class, goals:
o A consistent look and feel across the pages of the website
o Limit the amount of HTML needed to create a new page: easily
generate common parts, describe only uncommon parts
o Easy maintainable when changes in the common parts
o Flexible enough: ex. allow proper navigation elements in each page
19
Designing Classes
• Attributes:
o $content → content of the page, a combination of HTML and text
o $title → page’s title, with a default title to avoid blank titles
o $keywords → a list of keywords, to be used by search engines
o $navigation → an associative array with keys the text for the buttons
and the value the URL of the target page
• Operations:
o __set()
o Display() → to display a page of HTML, calls other functions to display
parts of the page:
o DisplayTitle(), DisplayKeywords(), DisplayStyles(), DisplayHeader(),
DisplayMenu(), DisplayFooter() → can be overridden in a possible
subclass
20
Class Page
ThankThank You !!!You !!!
For More Information click below link:
Follow Us on:
http://vibranttechnologies.co.in/php-classes-in-
mumbai.html

More Related Content

What's hot (20)

Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
CPD INDIA
 
Php Oop
Php OopPhp Oop
Php Oop
mussawir20
 
Oop in-php
Oop in-phpOop in-php
Oop in-php
Rajesh S
 
Object Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPObject Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOP
Wildan Maulana
 
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
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHP
Michael Peacock
 
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
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5
Jason Austin
 
Synapseindia object oriented programming in php
Synapseindia object oriented programming in phpSynapseindia object oriented programming in php
Synapseindia object oriented programming in php
Synapseindiappsdevelopment
 
Intermediate OOP in PHP
Intermediate OOP in PHPIntermediate OOP in PHP
Intermediate OOP in PHP
David Stockton
 
Class and Objects in PHP
Class and Objects in PHPClass and Objects in PHP
Class and Objects in PHP
Ramasubbu .P
 
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
 
Introduction to PHP OOP
Introduction to PHP OOPIntroduction to PHP OOP
Introduction to PHP OOP
fakhrul hasan
 
Oops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperOops in PHP By Nyros Developer
Oops in PHP By Nyros Developer
Nyros Technologies
 
Introduction to php oop
Introduction to php oopIntroduction to php oop
Introduction to php oop
baabtra.com - No. 1 supplier of quality freshers
 
Advanced php
Advanced phpAdvanced php
Advanced php
hamfu
 
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 oop presentation
Php   oop presentationPhp   oop presentation
Php oop presentation
Mutinda Boniface
 
Only oop
Only oopOnly oop
Only oop
anitarooge
 
Oops in php
Oops in phpOops in php
Oops in php
sanjay joshi
 

Viewers also liked (10)

O que esperar do Zend Framework 2
O que esperar do Zend Framework 2O que esperar do Zend Framework 2
O que esperar do Zend Framework 2
Flávio Lisboa
 
SQL Devlopment for 10 ppt
SQL Devlopment for 10 pptSQL Devlopment for 10 ppt
SQL Devlopment for 10 ppt
Tanay Kishore Mishra
 
Desenvolvimento Web com CakePHP
Desenvolvimento Web com CakePHPDesenvolvimento Web com CakePHP
Desenvolvimento Web com CakePHP
Sérgio Vilar
 
Workshop: WebSockets com HTML 5 & PHP - Gustavo Ciello
Workshop: WebSockets com HTML 5 & PHP - Gustavo CielloWorkshop: WebSockets com HTML 5 & PHP - Gustavo Ciello
Workshop: WebSockets com HTML 5 & PHP - Gustavo Ciello
Tchelinux
 
PHP 5.3 - Estruturas de Controle
PHP 5.3 - Estruturas de ControlePHP 5.3 - Estruturas de Controle
PHP 5.3 - Estruturas de Controle
George Mendonça
 
Css Ppt
Css PptCss Ppt
Css Ppt
Hema Prasanth
 
HTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPCHTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPC
Mayflower GmbH
 
Classroom Objects: PowerPoint Activities
Classroom Objects: PowerPoint ActivitiesClassroom Objects: PowerPoint Activities
Classroom Objects: PowerPoint Activities
A. Simoes
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
Karmatechnologies Pvt. Ltd.
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
O que esperar do Zend Framework 2
O que esperar do Zend Framework 2O que esperar do Zend Framework 2
O que esperar do Zend Framework 2
Flávio Lisboa
 
Desenvolvimento Web com CakePHP
Desenvolvimento Web com CakePHPDesenvolvimento Web com CakePHP
Desenvolvimento Web com CakePHP
Sérgio Vilar
 
Workshop: WebSockets com HTML 5 & PHP - Gustavo Ciello
Workshop: WebSockets com HTML 5 & PHP - Gustavo CielloWorkshop: WebSockets com HTML 5 & PHP - Gustavo Ciello
Workshop: WebSockets com HTML 5 & PHP - Gustavo Ciello
Tchelinux
 
PHP 5.3 - Estruturas de Controle
PHP 5.3 - Estruturas de ControlePHP 5.3 - Estruturas de Controle
PHP 5.3 - Estruturas de Controle
George Mendonça
 
HTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPCHTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPC
Mayflower GmbH
 
Classroom Objects: PowerPoint Activities
Classroom Objects: PowerPoint ActivitiesClassroom Objects: PowerPoint Activities
Classroom Objects: PowerPoint Activities
A. Simoes
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
Ad

Similar to PHP- Introduction to Object Oriented PHP (20)

Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1
Jalpesh Vasa
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
Sudip Simkhada
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
ShaownRoy1
 
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
c91632a4-2e92-4edf-b750-358da15ed1b1.pptxc91632a4-2e92-4edf-b750-358da15ed1b1.pptx
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
ajayparmeshwarmahaja
 
Oops concept in php
Oops concept in phpOops concept in php
Oops concept in php
selvabalaji k
 
Introduction to PHP and MySql basics.pptx
Introduction to PHP and MySql basics.pptxIntroduction to PHP and MySql basics.pptx
Introduction to PHP and MySql basics.pptx
PriyankaKupneshi
 
Oop in php tutorial
Oop in php tutorialOop in php tutorial
Oop in php tutorial
Gua Syed Al Yahya
 
oop_in_php_tutorial_for_killerphp.com
oop_in_php_tutorial_for_killerphp.comoop_in_php_tutorial_for_killerphp.com
oop_in_php_tutorial_for_killerphp.com
tutorialsruby
 
oop_in_php_tutorial_for_killerphp.com
oop_in_php_tutorial_for_killerphp.comoop_in_php_tutorial_for_killerphp.com
oop_in_php_tutorial_for_killerphp.com
tutorialsruby
 
Oop in php_tutorial_for_killerphp.com
Oop in php_tutorial_for_killerphp.comOop in php_tutorial_for_killerphp.com
Oop in php_tutorial_for_killerphp.com
ayandoesnotemail
 
Chap4 oop class (php) part 1
Chap4 oop class (php) part 1Chap4 oop class (php) part 1
Chap4 oop class (php) part 1
monikadeshmane
 
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
 
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
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
Tarek Mahmud Apu
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
Chhom Karath
 
Oop in php_tutorial
Oop in php_tutorialOop in php_tutorial
Oop in php_tutorial
Gregory Hanis
 
Oopsinphp
OopsinphpOopsinphp
Oopsinphp
NithyaNithyav
 
Object oriented programming in php
Object oriented programming in phpObject oriented programming in php
Object oriented programming in php
Aashiq Kuchey
 
Basic Oops concept of PHP
Basic Oops concept of PHPBasic Oops concept of PHP
Basic Oops concept of PHP
Rohan Sharma
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1
Jalpesh Vasa
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
ShaownRoy1
 
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
c91632a4-2e92-4edf-b750-358da15ed1b1.pptxc91632a4-2e92-4edf-b750-358da15ed1b1.pptx
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
ajayparmeshwarmahaja
 
Introduction to PHP and MySql basics.pptx
Introduction to PHP and MySql basics.pptxIntroduction to PHP and MySql basics.pptx
Introduction to PHP and MySql basics.pptx
PriyankaKupneshi
 
oop_in_php_tutorial_for_killerphp.com
oop_in_php_tutorial_for_killerphp.comoop_in_php_tutorial_for_killerphp.com
oop_in_php_tutorial_for_killerphp.com
tutorialsruby
 
oop_in_php_tutorial_for_killerphp.com
oop_in_php_tutorial_for_killerphp.comoop_in_php_tutorial_for_killerphp.com
oop_in_php_tutorial_for_killerphp.com
tutorialsruby
 
Oop in php_tutorial_for_killerphp.com
Oop in php_tutorial_for_killerphp.comOop in php_tutorial_for_killerphp.com
Oop in php_tutorial_for_killerphp.com
ayandoesnotemail
 
Chap4 oop class (php) part 1
Chap4 oop class (php) part 1Chap4 oop class (php) part 1
Chap4 oop class (php) part 1
monikadeshmane
 
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
 
Object oriented programming in php
Object oriented programming in phpObject oriented programming in php
Object oriented programming in php
Aashiq Kuchey
 
Basic Oops concept of PHP
Basic Oops concept of PHPBasic Oops concept of PHP
Basic Oops concept of PHP
Rohan Sharma
 
Ad

More from Vibrant Technologies & Computers (20)

Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5
Vibrant Technologies & Computers
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
Vibrant Technologies & Computers
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
Vibrant Technologies & Computers
 
SQL- Introduction to SQL database
SQL- Introduction to SQL database SQL- Introduction to SQL database
SQL- Introduction to SQL database
Vibrant Technologies & Computers
 
ITIL - introduction to ITIL
ITIL - introduction to ITILITIL - introduction to ITIL
ITIL - introduction to ITIL
Vibrant Technologies & Computers
 
Salesforce - Introduction to Security & Access
Salesforce -  Introduction to Security & Access Salesforce -  Introduction to Security & Access
Salesforce - Introduction to Security & Access
Vibrant Technologies & Computers
 
Data ware housing- Introduction to olap .
Data ware housing- Introduction to  olap .Data ware housing- Introduction to  olap .
Data ware housing- Introduction to olap .
Vibrant Technologies & Computers
 
Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.
Vibrant Technologies & Computers
 
Data ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housingData ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housing
Vibrant Technologies & Computers
 
Salesforce - classification of cloud computing
Salesforce - classification of cloud computingSalesforce - classification of cloud computing
Salesforce - classification of cloud computing
Vibrant Technologies & Computers
 
Salesforce - cloud computing fundamental
Salesforce - cloud computing fundamentalSalesforce - cloud computing fundamental
Salesforce - cloud computing fundamental
Vibrant Technologies & Computers
 
SQL- Introduction to PL/SQL
SQL- Introduction to  PL/SQLSQL- Introduction to  PL/SQL
SQL- Introduction to PL/SQL
Vibrant Technologies & Computers
 
SQL- Introduction to advanced sql concepts
SQL- Introduction to  advanced sql conceptsSQL- Introduction to  advanced sql concepts
SQL- Introduction to advanced sql concepts
Vibrant Technologies & Computers
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
Vibrant Technologies & Computers
 
SQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set OperationsSQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set Operations
Vibrant Technologies & Computers
 
Sas - Introduction to designing the data mart
Sas - Introduction to designing the data martSas - Introduction to designing the data mart
Sas - Introduction to designing the data mart
Vibrant Technologies & Computers
 
Sas - Introduction to working under change management
Sas - Introduction to working under change managementSas - Introduction to working under change management
Sas - Introduction to working under change management
Vibrant Technologies & Computers
 
SAS - overview of SAS
SAS - overview of SASSAS - overview of SAS
SAS - overview of SAS
Vibrant Technologies & Computers
 
Teradata - Architecture of Teradata
Teradata - Architecture of TeradataTeradata - Architecture of Teradata
Teradata - Architecture of Teradata
Vibrant Technologies & Computers
 
Teradata - Restoring Data
Teradata - Restoring Data Teradata - Restoring Data
Teradata - Restoring Data
Vibrant Technologies & Computers
 
Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.
Vibrant Technologies & Computers
 

Recently uploaded (20)

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
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdfENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptxFIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptxFIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdfWar_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
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
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptxFIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptxFIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
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
 
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
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API CatalogMuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
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
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdfENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptxFIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptxFIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdfWar_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
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
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptxFIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptxFIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
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
 
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
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API CatalogMuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 

PHP- Introduction to Object Oriented PHP

  • 3. • Topics: o OOP concepts – overview, throughout the chapter o Defining and using objects • Defining and instantiating classes • Defining and using variables, constants, and operations • Getters and setters o Defining and using inheritance and polymorphism • Building subclasses and overriding operations • Using interfaces o Advanced object-oriented functionality in PHP • Comparing objects, Printing objects, • Type hinting, Cloning objects, • Overloading methods, (some sections WILL NOT BE COVERED!!!) 3 Developing Object-Oriented PHP
  • 4. • Object-oriented programming (OOP) refers to the creation of reusable software object-types / classes that can be efficiently developed and easily incorporated into multiple programs. • In OOP an object represents an entity in the real world (a student, a desk, a button, a file, a text input area, a loan, a web page, a shopping cart). • An OOP program = a collection of objects that interact to solve a task / problem. 4 Object-Oriented Programming
  • 5. • Objects are self-contained, with data and operations that pertain to them assembled into a single entity. o In procedural programming data and operations are separate → this methodology requires sending data to methods! • Objects have: o Identity; ex: 2 “OK” buttons, same attributes → separate handle vars o State → a set of attributes (aka member variables, properties, data fields) = properties or variables that relate to / describe the object, with their current values. o Behavior → a set of operations (aka methods) = actions or functions that the object can perform to modify itself – its state, or perform for some external effect / result. 5 Object-Oriented Programming
  • 6. • Encapsulation (aka data hiding) central in OOP o = access to data within an object is available only via the object’s operations (= known as the interface of the object) o = internal aspects of objects are hidden, wrapped as a birthday present is wrapped by colorful paper  • Advantages: o objects can be used as black-boxes, if their interface is known; o implementation of an interface can be changed without a cascading effect to other parts of the project → if the interface doesn’t change 6 Object-Oriented Programming
  • 7. • Classes are constructs that define objects of the same type. A class is a template or blueprint that defines what an object’s data and methods will be. Objects of a class have: o Same operations, behaving the same way o Same attributes representing the same features, but values of those attributes (= state) can vary from object to object • An object is an instance of a class. (terms objects and instances are used interchangeably) • Any number of instances of a class can be created. 7 Object-Oriented Programming
  • 8. • Small Web projects o Consist of web scripts designed and written using an ad-hoc approach; a function-oriented, procedural methodology • Large Web software projects o Need a properly thought-out development methodology – OOP → o OO approach can help manage project complexity, increase code reusability, reduce costs. o OO analysis and design process = decide what object types, what hidden data/operations and wrapper operations for each object type o UML – as tool in OO design, to allow to describe classes and class relationships 8 OOP in Web Programming
  • 9. • A minimal class definition: class classname { // classname is a PHP identifier! // the class body = data & function member definitions } • Attributes o are declared as variables within the class definition using keywords that match their visibility: public, private, or protected. (Recall that PHP doesn't otherwise have declarations of variables → data member declarations against the nature of PHP?) • Operations o are created by declaring functions within the class definition. 9 Creating Classes in PHP
  • 10. • Constructor = function used to create an object of the class o Declared as a function with a special name: function __construct (param_list) { … } o Usually performs initialization tasks: e.g. sets attributes to appropriate starting values o Called automatically when an object is created o A default no-argument constructor is provided by the compiler only if a constructor function is not explicitly declared in the class o Cannot be overloaded (= 2+ constructors for a class); if you need a variable # of parameters, use flexible parameter lists… 10 Creating Classes in PHP
  • 11. • Destructor = opposite of constructor o Declared as a function with a special name, cannot take parameters function __destruct () { … } o Allows some functionality that will be automatically executed just before an object is destroyed  An object is removed when there is no reference variable/handle left to it  Usually during the "script shutdown phase", which is typically right before the execution of the PHP script finishes o A default destructor provided by the compiler only if a destructor function is not explicitly declared in the class 11 Creating Classes in PHP
  • 12. • Create an object of a class = a particular individual that is a member of the class by using the new keyword: $newClassVariable = new ClassName(actual_param_list); • Notes: o Scope for PHP classes is global (program script level), as it is for functions o Class names are case insensitive as are functions o PHP 5 allows you to define multiple classes in a single program script o The PHP parser reads classes into memory immediately after functions ⇒ class construction does not fail because a class is not previously defined in the program scope. 12 Instantiating Classes
  • 13. • From operations within the class, class’s data / methods can be accessed / called by using: o $this = a variable that refers to the current instance of the class, and can be used only in the definition of the class, including the constructor & destructor o The pointer operator -> (similar to Java’s object member access operator “.” ) o class Test { public $attribute; function f ($val) { $this -> attribute = $val; // $this is mandatory! } // if omitted, $attribute is treated } // as a local var in the function 13 Using Data/Method Members No $ sign here
  • 14. • From outside the class, accessible (as determined by access modifiers) data and methods are accessed through a variable holding an instance of the class, by using the same pointer operator. class Test { public $attribute; } $t = new Test(); $t->attribute = “value”; echo $t->attribute; 14 Using Data/Method Members
  • 15. • Three access / visibility modifiers introduced in PHP 5, which affect the scope of access to class variables and functions: o public : public class variables and functions can be accessed from inside and outside the class o protected : hides a variable or function from direct external class access + protected members are available in subclasses o private : hides a variable or function from direct external class access + protected members are hidden (NOT available) from all subclasses • An access modifier has to be provided for each class instance variable • Static class variables and functions can be declared without an access modifier → default is public 15 Defining and Using Variables, Constants and Functions
  • 16. • Encapsulation : hide attributes from direct access from outside a class and provide controlled access through accessor and mutator functions o You can write custom getVariable() / setVariable($var) functions or o Overload the functionality with the __get() and __set() functions in PHP • __get() and __set() o Prototype: mixed __get($var); // param represents the name of an attribute, __get returns the value of that attribute void __set($var, $value); // params are the name of an attribute and the value to set it to 16 Getters and Setters
  • 17. • __get() and __set() o Can only be used for non-static attributes! o You do not directly call these functions; For an instance $acc of the BankAccount class: $acc->Balance = 1000; implicitly calls the __set() function with the value of $name set to ‘Balance’, and the value of $value set to 1000. (__get() works in a similar way) 17 Getters and Setters
  • 18. • __get() and __set() functions’ value: a single access point to an attribute ensures complete control over: o attribute’s values function __set($name, $value) { echo "<p>Setter for $name called!</p>"; if (strcasecmp($name, "Balance")==0 && ($value>=0)) $this->$name = $value; ... } o underlying implementation: as a variable, retrieved from a db when needed, a value inferred based on the values of other attributes → transparent for clients as long as the accessor / mutator18 Getters and Setters
  • 19. • Classes in Web development: o Pages o User-interface components o Shopping carts o Product categories o Customers • TLA Consulting example revisited - a Page class, goals: o A consistent look and feel across the pages of the website o Limit the amount of HTML needed to create a new page: easily generate common parts, describe only uncommon parts o Easy maintainable when changes in the common parts o Flexible enough: ex. allow proper navigation elements in each page 19 Designing Classes
  • 20. • Attributes: o $content → content of the page, a combination of HTML and text o $title → page’s title, with a default title to avoid blank titles o $keywords → a list of keywords, to be used by search engines o $navigation → an associative array with keys the text for the buttons and the value the URL of the target page • Operations: o __set() o Display() → to display a page of HTML, calls other functions to display parts of the page: o DisplayTitle(), DisplayKeywords(), DisplayStyles(), DisplayHeader(), DisplayMenu(), DisplayFooter() → can be overridden in a possible subclass 20 Class Page
  • 21. ThankThank You !!!You !!! For More Information click below link: Follow Us on: http://vibranttechnologies.co.in/php-classes-in- mumbai.html

Editor's Notes

  • #10: Public can be replaced with var -&amp;gt; public visibility by default!
  • #12: If ref var is assigned null -&amp;gt; destructor called if no other ref var left to that object!