SlideShare a Scribd company logo
Object-Oriented Programming with PHP
Part 1
by Bozhidar Boshnakov
Recap
• We talked about
– Loops
– Conditional statements
– Functions and return values
– Include and require
– Variables scope
Table of contents
• Classes and objects
• Methods and properties
• Scope
• The idea of Object Oriented Programming is
to move the architecture of an application
closer to real world
– Classes are types of entities
– Objects are single units of a given class
– Example – Dog is a class, your dog Lassie is an
object of class Dog
– Classes have methods and properties
– Classes and objects help to create well-
structured application
• Declaring of a class in PHP can be done
anywhere in the code
– Two special methods: constructor and destructor
• Executed when creating or destroying new object of
this class
• Used to initialize or cleanup properties and etc.
class Dog {
… // declare methods and properties
}
• Class definition begins with the class
keyword, followed by its name and methods
and properties list
– Objects of class (instances) are created with the
keyword new
class A {
function foo () {
echo "foo here!";
}
}
$myFirstObject = new A();
$myFirstObject->foo(); // prints out "foo here!";
• Each class can have only one constructor
– All parameters of the creating of the object are
passed to the constructor
class A {
function __construct ($bar) {
echo $bar;
}
function foo () {
echo "foo here!";
}
}
$myFirstObject = new A('test');
// print 'test'
• Class can have unlimited number of properties
• The $this variable points to the current object –
called execution context
class A {
var $bar;
function __construct ($bar) {
$this->bar = $bar;
}
function myPrint () {
echo $this->bar;
}
}
$myFirstObject = new A('test');
$myFirstObject->myPrint();
• Class can specify default value for a property
• Properties can be accessed from the outside
world
class A {
var $bar = 'default value';
…
class A {
var $bar = 'default value';
…
}
$obj = new A;
echo $obj->bar;
• Example of what $this is
• Can be used to access methods too
class A {
var $bar;
function __construct ($bar) {
$this->bar = $bar;
}
function myPrint () {
echo $this->bar;
}
}
$myFirstObject = new A('test');
$myFirstObject->myPrint(); // prints 'test'
$anotherObject = new A('foo');
$anotherObject ->myPrint(); // prints 'foo';
• Each class can have only one destructor
– Must be public
– Destructors are automatically called when script
is shutting down
class A {
function __construct ($name) {
$this->fp = fopen ($name, 'r');
}
function __destruct () {
fclose($this->fp);
}
}
$myFirstObject = new A('test');
• Each method and property has a scope
– It defines who can access it
– Three levels – public, protected, private
• Private can be access only by the object itself
• Protected can be accessed by descendant classes (see
inheritance)
• Public can be accessed from the outside world
– Level is added before function keyword or
instead of var
• var is old style (PHP 4) equivalent to public
– Constructors always need to be public
class A {
private $bar;
public function __construct ($bar) {
$this->bar = $bar;
}
public function myPrint () {
echo $this->bar;
}
}
$myFirstObject = new A('test');
$myFirstObject->myPrint(); // prints 'test'
// this will not work:
echo $myFirstObject->bar;
• Resources
– http://php-uroci.devbg.org/
– http://academy.telerik.com/
– http://www.codecademy.com/
Object-Oriented Programming with PHP (part 1)

More Related Content

What's hot (20)

php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in function
tumetr1
 
PHP variables
PHP  variablesPHP  variables
PHP variables
Siddique Ibrahim
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
Nikita Popov
 
Functions in PHP
Functions in PHPFunctions in PHP
Functions in PHP
Vineet Kumar Saini
 
Syntax
SyntaxSyntax
Syntax
Krasimir Berov (Красимир Беров)
 
DIG1108 Lesson 6
DIG1108 Lesson 6DIG1108 Lesson 6
DIG1108 Lesson 6
vc-dig1108-fall-2013
 
Arrays & functions in php
Arrays & functions in phpArrays & functions in php
Arrays & functions in php
Ashish Chamoli
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
Fwdays
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
Object Oriented PHP - PART-2
Object Oriented PHP - PART-2Object Oriented PHP - PART-2
Object Oriented PHP - PART-2
Jalpesh Vasa
 
Scripting3
Scripting3Scripting3
Scripting3
Nao Dara
 
SQL Devlopment for 10 ppt
SQL Devlopment for 10 pptSQL Devlopment for 10 ppt
SQL Devlopment for 10 ppt
Tanay Kishore Mishra
 
Further Php
Further PhpFurther Php
Further Php
Digital Insights - Digital Marketing Agency
 
Php variables
Php variablesPhp variables
Php variables
Ritwik Das
 
PHP 8.1 - What's new and changed
PHP 8.1 - What's new and changedPHP 8.1 - What's new and changed
PHP 8.1 - What's new and changed
Ayesh Karunaratne
 
Improving Dev Assistant
Improving Dev AssistantImproving Dev Assistant
Improving Dev Assistant
Dave Cross
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
Lin Yo-An
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
rhshriva
 
(Parameterized) Roles
(Parameterized) Roles(Parameterized) Roles
(Parameterized) Roles
sartak
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
anshkhurana01
 
php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in function
tumetr1
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
Nikita Popov
 
Arrays & functions in php
Arrays & functions in phpArrays & functions in php
Arrays & functions in php
Ashish Chamoli
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
Fwdays
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
Object Oriented PHP - PART-2
Object Oriented PHP - PART-2Object Oriented PHP - PART-2
Object Oriented PHP - PART-2
Jalpesh Vasa
 
Scripting3
Scripting3Scripting3
Scripting3
Nao Dara
 
PHP 8.1 - What's new and changed
PHP 8.1 - What's new and changedPHP 8.1 - What's new and changed
PHP 8.1 - What's new and changed
Ayesh Karunaratne
 
Improving Dev Assistant
Improving Dev AssistantImproving Dev Assistant
Improving Dev Assistant
Dave Cross
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
Lin Yo-An
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
rhshriva
 
(Parameterized) Roles
(Parameterized) Roles(Parameterized) Roles
(Parameterized) Roles
sartak
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
anshkhurana01
 

Viewers also liked (10)

Как да направим живота си по - лесен с добър QA подход
Как да направим живота си по - лесен с добър QA подходКак да направим живота си по - лесен с добър QA подход
Как да направим живота си по - лесен с добър QA подход
Bozhidar Boshnakov
 
Demystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHPDemystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHP
Alena Holligan
 
PHP Experience 2016 - ROA – Resource Oriented Architecture
PHP Experience 2016 - ROA – Resource Oriented ArchitecturePHP Experience 2016 - ROA – Resource Oriented Architecture
PHP Experience 2016 - ROA – Resource Oriented Architecture
iMasters
 
Simple Web Services with PHP
Simple Web Services with PHPSimple Web Services with PHP
Simple Web Services with PHP
John Paul Ada
 
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016 Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Alexander Lisachenko
 
WebCamp 2016: PHP. Николай Паламарчук: PHP и микросервисы
WebCamp 2016: PHP. Николай Паламарчук: PHP и микросервисыWebCamp 2016: PHP. Николай Паламарчук: PHP и микросервисы
WebCamp 2016: PHP. Николай Паламарчук: PHP и микросервисы
WebCamp
 
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
Alexandre Brandão Lustosa
 
浅谈电商网站数据访问层(DAL)与 ORM 之适用性
浅谈电商网站数据访问层(DAL)与 ORM 之适用性浅谈电商网站数据访问层(DAL)与 ORM 之适用性
浅谈电商网站数据访问层(DAL)与 ORM 之适用性
Xuefeng Zhang
 
Process Oriented Architecture
Process Oriented ArchitectureProcess Oriented Architecture
Process Oriented Architecture
Alan McSweeney
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
Andrew Rota
 
Как да направим живота си по - лесен с добър QA подход
Как да направим живота си по - лесен с добър QA подходКак да направим живота си по - лесен с добър QA подход
Как да направим живота си по - лесен с добър QA подход
Bozhidar Boshnakov
 
Demystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHPDemystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHP
Alena Holligan
 
PHP Experience 2016 - ROA – Resource Oriented Architecture
PHP Experience 2016 - ROA – Resource Oriented ArchitecturePHP Experience 2016 - ROA – Resource Oriented Architecture
PHP Experience 2016 - ROA – Resource Oriented Architecture
iMasters
 
Simple Web Services with PHP
Simple Web Services with PHPSimple Web Services with PHP
Simple Web Services with PHP
John Paul Ada
 
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016 Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Alexander Lisachenko
 
WebCamp 2016: PHP. Николай Паламарчук: PHP и микросервисы
WebCamp 2016: PHP. Николай Паламарчук: PHP и микросервисыWebCamp 2016: PHP. Николай Паламарчук: PHP и микросервисы
WebCamp 2016: PHP. Николай Паламарчук: PHP и микросервисы
WebCamp
 
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
Alexandre Brandão Lustosa
 
浅谈电商网站数据访问层(DAL)与 ORM 之适用性
浅谈电商网站数据访问层(DAL)与 ORM 之适用性浅谈电商网站数据访问层(DAL)与 ORM 之适用性
浅谈电商网站数据访问层(DAL)与 ORM 之适用性
Xuefeng Zhang
 
Process Oriented Architecture
Process Oriented ArchitectureProcess Oriented Architecture
Process Oriented Architecture
Alan McSweeney
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
Andrew Rota
 
Ad

Similar to Object-Oriented Programming with PHP (part 1) (20)

Object Oriented Programming in PHP
Object Oriented Programming  in PHPObject Oriented Programming  in PHP
Object Oriented Programming in PHP
wahidullah mudaser
 
Introduction to php oop
Introduction to php oopIntroduction to php oop
Introduction to php oop
baabtra.com - No. 1 supplier of quality freshers
 
Synapseindia object oriented programming in php
Synapseindia object oriented programming in phpSynapseindia object oriented programming in php
Synapseindia object oriented programming in php
Synapseindiappsdevelopment
 
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
c91632a4-2e92-4edf-b750-358da15ed1b1.pptxc91632a4-2e92-4edf-b750-358da15ed1b1.pptx
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
ajayparmeshwarmahaja
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
Chhom Karath
 
Oops concept in php
Oops concept in phpOops concept in php
Oops concept in php
selvabalaji k
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
Henry Osborne
 
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
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1
Jalpesh Vasa
 
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
 
09 Object Oriented Programming in PHP #burningkeyboards
09 Object Oriented Programming in PHP #burningkeyboards09 Object Oriented Programming in PHP #burningkeyboards
09 Object Oriented Programming in PHP #burningkeyboards
Denis Ristic
 
Web 9 | OOP in PHP
Web 9 | OOP in PHPWeb 9 | OOP in PHP
Web 9 | OOP in PHP
Mohammad Imam Hossain
 
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
 
Advanced php
Advanced phpAdvanced php
Advanced php
hamfu
 
Only oop
Only oopOnly oop
Only oop
anitarooge
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
Tarek Mahmud Apu
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
ShaownRoy1
 
Object oriented programming in php
Object oriented programming in phpObject oriented programming in php
Object oriented programming in php
Aashiq Kuchey
 
Oops in php
Oops in phpOops in php
Oops in php
Gourishankar R Pujar
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5
Jason Austin
 
Ad

More from Bozhidar Boshnakov (8)

Mission possible - revival
Mission possible - revivalMission possible - revival
Mission possible - revival
Bozhidar Boshnakov
 
Web fundamentals 2
Web fundamentals 2Web fundamentals 2
Web fundamentals 2
Bozhidar Boshnakov
 
Web fundamentals - part 1
Web fundamentals - part 1Web fundamentals - part 1
Web fundamentals - part 1
Bozhidar Boshnakov
 
PMG Gabrovo - Web Development Level 0 - Introduction
PMG Gabrovo - Web Development Level 0 - IntroductionPMG Gabrovo - Web Development Level 0 - Introduction
PMG Gabrovo - Web Development Level 0 - Introduction
Bozhidar Boshnakov
 
QA Challange Accepted - How and why we should use Behat?
QA Challange Accepted - How and why we should use Behat?QA Challange Accepted - How and why we should use Behat?
QA Challange Accepted - How and why we should use Behat?
Bozhidar Boshnakov
 
DrupalCamp Sofia 2015
DrupalCamp Sofia 2015DrupalCamp Sofia 2015
DrupalCamp Sofia 2015
Bozhidar Boshnakov
 
BDD, Behat & Drupal
BDD, Behat & DrupalBDD, Behat & Drupal
BDD, Behat & Drupal
Bozhidar Boshnakov
 
Automation in Drupal
Automation in DrupalAutomation in Drupal
Automation in Drupal
Bozhidar Boshnakov
 

Recently uploaded (20)

Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
Revolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management SoftwareRevolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management Software
Insurance Tech Services
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FMEIntegrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdfHow to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
victordsane
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptxHow AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
kalichargn70th171
 
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
SheenBrisals
 
Rebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core FoundationRebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core Foundation
Cadabra Studio
 
Topic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptxTopic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptx
marutnand8
 
Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...
Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...
Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...
Safe Software
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!
PhilMeredith3
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
Revolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management SoftwareRevolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management Software
Insurance Tech Services
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FMEIntegrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdfHow to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
victordsane
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptxHow AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
kalichargn70th171
 
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
SheenBrisals
 
Rebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core FoundationRebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core Foundation
Cadabra Studio
 
Topic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptxTopic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptx
marutnand8
 
Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...
Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...
Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...
Safe Software
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!
PhilMeredith3
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 

Object-Oriented Programming with PHP (part 1)

  • 1. Object-Oriented Programming with PHP Part 1 by Bozhidar Boshnakov
  • 2. Recap • We talked about – Loops – Conditional statements – Functions and return values – Include and require – Variables scope
  • 3. Table of contents • Classes and objects • Methods and properties • Scope
  • 4. • The idea of Object Oriented Programming is to move the architecture of an application closer to real world – Classes are types of entities – Objects are single units of a given class – Example – Dog is a class, your dog Lassie is an object of class Dog – Classes have methods and properties – Classes and objects help to create well- structured application
  • 5. • Declaring of a class in PHP can be done anywhere in the code – Two special methods: constructor and destructor • Executed when creating or destroying new object of this class • Used to initialize or cleanup properties and etc. class Dog { … // declare methods and properties }
  • 6. • Class definition begins with the class keyword, followed by its name and methods and properties list – Objects of class (instances) are created with the keyword new class A { function foo () { echo "foo here!"; } } $myFirstObject = new A(); $myFirstObject->foo(); // prints out "foo here!";
  • 7. • Each class can have only one constructor – All parameters of the creating of the object are passed to the constructor class A { function __construct ($bar) { echo $bar; } function foo () { echo "foo here!"; } } $myFirstObject = new A('test'); // print 'test'
  • 8. • Class can have unlimited number of properties • The $this variable points to the current object – called execution context class A { var $bar; function __construct ($bar) { $this->bar = $bar; } function myPrint () { echo $this->bar; } } $myFirstObject = new A('test'); $myFirstObject->myPrint();
  • 9. • Class can specify default value for a property • Properties can be accessed from the outside world class A { var $bar = 'default value'; … class A { var $bar = 'default value'; … } $obj = new A; echo $obj->bar;
  • 10. • Example of what $this is • Can be used to access methods too class A { var $bar; function __construct ($bar) { $this->bar = $bar; } function myPrint () { echo $this->bar; } } $myFirstObject = new A('test'); $myFirstObject->myPrint(); // prints 'test' $anotherObject = new A('foo'); $anotherObject ->myPrint(); // prints 'foo';
  • 11. • Each class can have only one destructor – Must be public – Destructors are automatically called when script is shutting down class A { function __construct ($name) { $this->fp = fopen ($name, 'r'); } function __destruct () { fclose($this->fp); } } $myFirstObject = new A('test');
  • 12. • Each method and property has a scope – It defines who can access it – Three levels – public, protected, private • Private can be access only by the object itself • Protected can be accessed by descendant classes (see inheritance) • Public can be accessed from the outside world – Level is added before function keyword or instead of var • var is old style (PHP 4) equivalent to public – Constructors always need to be public
  • 13. class A { private $bar; public function __construct ($bar) { $this->bar = $bar; } public function myPrint () { echo $this->bar; } } $myFirstObject = new A('test'); $myFirstObject->myPrint(); // prints 'test' // this will not work: echo $myFirstObject->bar;
  • 14. • Resources – http://php-uroci.devbg.org/ – http://academy.telerik.com/ – http://www.codecademy.com/