SlideShare une entreprise Scribd logo
1  sur  19
B-Tech CSE 6th
13/NR/UT/CS005
Submitted by :- Shivani Soni
Submitted to :- Shivani Dhiman
 PHP is an open source , server-side scripting
language.
 PHP is used to generate dynamic web pages.
 Originally created by Rasmus Lerdorf in 1994,
the PHP reference implementation is now
produced by The PHP Group.PHP originally
stood for Personal Home Page , but it now
stands for Hypertext Preprocessor
PHP scripts reside between reserved PHP tags .
This php tags allows the programmer to embed
php scripts with in HTML pages.
 Free
 Multi OS Support(like linux,windows,OSX)
 Easier to fix problem
 Easy to understand
 Speed
 Object oriented
 Compatible with many databases(SQL,MySQL)
 Simple efficient
 Secure flexible
 familiar
 PHP is also OOP language as it also
based on the concepts of object and
classes. PHP also uses the object
oriented concepts like encapsulation ,
inheritance , polymorphism , data
abstraction and constructors.
Class-: classes are the "blueprints“ for an
object and the actual code that defines the
properties and methods . and the class is
declared with in the tags.
Objects-: An object is an instance
of a class.
Any number of instances
of a class can be created.
<?php
class pen
{
}
?>
 <?php
 Class house
 {
 Public $name=“Soni”;
 Public $age=47;
 Function hello()
 {
 Echo “Hello world”;
 }
 $h=new house();
 $g=new house();
 Echo $h->name . “is” .$h->age .”year old”;
 Echo $g->hello ()
 ?>
 The output is-:soni is 47 year old hello world
 Define:-Encapsulation is just wrapping of data in single
unit also we can say hiding the information of essential
details . Or we can say that it is the process of hiding the data
of the object from outside world and accessed to it is
restricted to members of the class.
 Example:- Let You have a mobile phone…there it some
interface which help You to interact with cell phone and you
can uses the services of mobile phone. But the actually
working in cell phone is hide. You don’t know how it works
internally.
 <?php
 class App {
 private static $_user;
 public function User( ) {
 if( $this->_user == null ) {
 $this->_user = new User();
 }
 return $this->_user;
 }
 }
 class User {
 private $_name;
 public function __construct() {
 $this->_name = “Shivani";
 }
 public function GetName() {
 return $this->_name;
 }
 }
 $app = new App();
 echo $app->User()->GetName();
 ?>
 If a class name and function name will be
similar in that case function is known as
constructor. constructor is special type of
method because its name is similar to class
name . constructor automatically calls when
object will be initializing.
 There are two types of constructor
 1) user defined constructor
 2) predefined constructor
 Note:-here we have called testA() method but
we didn’t call A() method because it
automatically called when object is initialized.
 PHP introduce a new functionality to
define a constructor i.e __construct().
 By using this function we can define a
constructor. it is known as predefined
constructor.
 __construct() are also known as magic
function in PHP.
 <?php
 class BaseClass {
 function __construct()
 {
 echo "Shivanin";
 }
 }
 class SubClass extends BaseClass
 {
 function __construct()
 {
 parent::__construct();
 echo “sonin";
 }
 }
 $obj = new BaseClass();
 $obj = new SubClass();
 ?>
Constructor and encapsulation in php
Constructor and encapsulation in php

Contenu connexe

Tendances

Mobile application development React Native - Tidepool Labs
Mobile application development React Native - Tidepool LabsMobile application development React Native - Tidepool Labs
Mobile application development React Native - Tidepool LabsHarutyun Abgaryan
 
Bootstrap 5 whats new
Bootstrap 5   whats newBootstrap 5   whats new
Bootstrap 5 whats newSandun Perera
 
HTML5 introduction for beginners
HTML5 introduction for beginnersHTML5 introduction for beginners
HTML5 introduction for beginnersVineeth N Krishnan
 
Bootstrap Part - 1
Bootstrap Part - 1Bootstrap Part - 1
Bootstrap Part - 1EPAM Systems
 
Net Maui Blazor Jornada ASP Net en Español.pptx
Net Maui Blazor Jornada ASP Net en Español.pptxNet Maui Blazor Jornada ASP Net en Español.pptx
Net Maui Blazor Jornada ASP Net en Español.pptxLuis775803
 
Cascading style sheets (CSS)
Cascading style sheets (CSS)Cascading style sheets (CSS)
Cascading style sheets (CSS)Harshita Yadav
 
Java script Basic
Java script BasicJava script Basic
Java script BasicJaya Kumari
 
Creating a frame within an applet
Creating a frame within an appletCreating a frame within an applet
Creating a frame within an appletmyrajendra
 
Flutter presentation.pptx
Flutter presentation.pptxFlutter presentation.pptx
Flutter presentation.pptxFalgunSorathiya
 
Webinar - Desarrollo con Oracle Application Express (APEX): demostración prác...
Webinar - Desarrollo con Oracle Application Express (APEX): demostración prác...Webinar - Desarrollo con Oracle Application Express (APEX): demostración prác...
Webinar - Desarrollo con Oracle Application Express (APEX): demostración prác...avanttic Consultoría Tecnológica
 
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...Edureka!
 
Google Maps API - DevFest Karlsruhe
Google Maps API - DevFest Karlsruhe Google Maps API - DevFest Karlsruhe
Google Maps API - DevFest Karlsruhe Martin Kleppe
 
Introduction to flutter's basic concepts
Introduction to flutter's basic conceptsIntroduction to flutter's basic concepts
Introduction to flutter's basic conceptsKumaresh Chandra Baruri
 

Tendances (20)

Mobile application development React Native - Tidepool Labs
Mobile application development React Native - Tidepool LabsMobile application development React Native - Tidepool Labs
Mobile application development React Native - Tidepool Labs
 
Bootstrap 5 whats new
Bootstrap 5   whats newBootstrap 5   whats new
Bootstrap 5 whats new
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
HTML5 introduction for beginners
HTML5 introduction for beginnersHTML5 introduction for beginners
HTML5 introduction for beginners
 
APEX Themes and Templates
APEX Themes and TemplatesAPEX Themes and Templates
APEX Themes and Templates
 
Bootstrap 5 basic
Bootstrap 5 basicBootstrap 5 basic
Bootstrap 5 basic
 
Bootstrap 5 ppt
Bootstrap 5 pptBootstrap 5 ppt
Bootstrap 5 ppt
 
Bootstrap Part - 1
Bootstrap Part - 1Bootstrap Part - 1
Bootstrap Part - 1
 
CSS media types
CSS media typesCSS media types
CSS media types
 
Web programming
Web programmingWeb programming
Web programming
 
Net Maui Blazor Jornada ASP Net en Español.pptx
Net Maui Blazor Jornada ASP Net en Español.pptxNet Maui Blazor Jornada ASP Net en Español.pptx
Net Maui Blazor Jornada ASP Net en Español.pptx
 
Cascading style sheets (CSS)
Cascading style sheets (CSS)Cascading style sheets (CSS)
Cascading style sheets (CSS)
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Creating a frame within an applet
Creating a frame within an appletCreating a frame within an applet
Creating a frame within an applet
 
Flutter presentation.pptx
Flutter presentation.pptxFlutter presentation.pptx
Flutter presentation.pptx
 
Webinar - Desarrollo con Oracle Application Express (APEX): demostración prác...
Webinar - Desarrollo con Oracle Application Express (APEX): demostración prác...Webinar - Desarrollo con Oracle Application Express (APEX): demostración prác...
Webinar - Desarrollo con Oracle Application Express (APEX): demostración prác...
 
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
 
Google Maps API - DevFest Karlsruhe
Google Maps API - DevFest Karlsruhe Google Maps API - DevFest Karlsruhe
Google Maps API - DevFest Karlsruhe
 
Introduction to flutter's basic concepts
Introduction to flutter's basic conceptsIntroduction to flutter's basic concepts
Introduction to flutter's basic concepts
 

En vedette (20)

PHP
PHPPHP
PHP
 
Php variables (english)
Php variables (english)Php variables (english)
Php variables (english)
 
Font
FontFont
Font
 
OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
Htmltag.ppt
Htmltag.pptHtmltag.ppt
Htmltag.ppt
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
Execute MySQL query using command prompt
Execute MySQL query using command promptExecute MySQL query using command prompt
Execute MySQL query using command prompt
 
What's new in PHP 7.1
What's new in PHP 7.1What's new in PHP 7.1
What's new in PHP 7.1
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 
Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In Php
 
PHP variables
PHP  variablesPHP  variables
PHP variables
 
State management
State managementState management
State management
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
Execute sql query or sql command sql server using command prompt
Execute sql query or sql command sql server using command promptExecute sql query or sql command sql server using command prompt
Execute sql query or sql command sql server using command prompt
 
Php forms
Php formsPhp forms
Php forms
 
Cookie and session
Cookie and sessionCookie and session
Cookie and session
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 

Similaire à Constructor and encapsulation in php

Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPsRavi Bhadauria
 
PHP in one presentation
PHP in one presentationPHP in one presentation
PHP in one presentationMilad Rahimi
 
C#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersC#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersSanjaya Prakash Pradhan
 
Introduction to PHP OOP
Introduction to PHP OOPIntroduction to PHP OOP
Introduction to PHP OOPfakhrul hasan
 
Basic Oops concept of PHP
Basic Oops concept of PHPBasic Oops concept of PHP
Basic Oops concept of PHPRohan Sharma
 
Embrace dynamic PHP
Embrace dynamic PHPEmbrace dynamic PHP
Embrace dynamic PHPPaul Houle
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxShaownRoy1
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010Rich Helton
 
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.comtutorialsruby
 
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.comtutorialsruby
 
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.comayandoesnotemail
 

Similaire à Constructor and encapsulation in php (20)

Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPs
 
PHP in one presentation
PHP in one presentationPHP in one presentation
PHP in one presentation
 
C#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersC#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developers
 
Oop's in php
Oop's in php Oop's in php
Oop's in php
 
Introduction to PHP OOP
Introduction to PHP OOPIntroduction to PHP OOP
Introduction to PHP OOP
 
Oops in PHP
Oops in PHPOops in PHP
Oops in PHP
 
Basic Oops concept of PHP
Basic Oops concept of PHPBasic Oops concept of PHP
Basic Oops concept of PHP
 
Oops in php
Oops in phpOops in php
Oops in php
 
Introduction Php
Introduction PhpIntroduction Php
Introduction Php
 
Embrace dynamic PHP
Embrace dynamic PHPEmbrace dynamic PHP
Embrace dynamic PHP
 
php questions
php questions php questions
php questions
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
 
Php oop presentation
Php   oop presentationPhp   oop presentation
Php oop presentation
 
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
 
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
 
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
 

Dernier

NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...Amil Baba Dawood bangali
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxVelmuruganTECE
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptMadan Karki
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESNarmatha D
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxsiddharthjain2303
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdfCaalaaAbdulkerim
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 

Dernier (20)

NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptx
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.ppt
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIES
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptx
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdf
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 

Constructor and encapsulation in php

  • 1. B-Tech CSE 6th 13/NR/UT/CS005 Submitted by :- Shivani Soni Submitted to :- Shivani Dhiman
  • 2.  PHP is an open source , server-side scripting language.  PHP is used to generate dynamic web pages.  Originally created by Rasmus Lerdorf in 1994, the PHP reference implementation is now produced by The PHP Group.PHP originally stood for Personal Home Page , but it now stands for Hypertext Preprocessor
  • 3. PHP scripts reside between reserved PHP tags . This php tags allows the programmer to embed php scripts with in HTML pages.
  • 4.  Free  Multi OS Support(like linux,windows,OSX)  Easier to fix problem  Easy to understand  Speed  Object oriented  Compatible with many databases(SQL,MySQL)  Simple efficient  Secure flexible  familiar
  • 5.  PHP is also OOP language as it also based on the concepts of object and classes. PHP also uses the object oriented concepts like encapsulation , inheritance , polymorphism , data abstraction and constructors.
  • 6. Class-: classes are the "blueprints“ for an object and the actual code that defines the properties and methods . and the class is declared with in the tags. Objects-: An object is an instance of a class. Any number of instances of a class can be created. <?php class pen { } ?>
  • 7.  <?php  Class house  {  Public $name=“Soni”;  Public $age=47;  Function hello()  {  Echo “Hello world”;  }  $h=new house();  $g=new house();  Echo $h->name . “is” .$h->age .”year old”;  Echo $g->hello ()  ?>  The output is-:soni is 47 year old hello world
  • 8.  Define:-Encapsulation is just wrapping of data in single unit also we can say hiding the information of essential details . Or we can say that it is the process of hiding the data of the object from outside world and accessed to it is restricted to members of the class.  Example:- Let You have a mobile phone…there it some interface which help You to interact with cell phone and you can uses the services of mobile phone. But the actually working in cell phone is hide. You don’t know how it works internally.
  • 9.  <?php  class App {  private static $_user;  public function User( ) {  if( $this->_user == null ) {  $this->_user = new User();  }  return $this->_user;  }  }
  • 10.  class User {  private $_name;  public function __construct() {  $this->_name = “Shivani";  }  public function GetName() {  return $this->_name;  }  }  $app = new App();  echo $app->User()->GetName();  ?>
  • 11.  If a class name and function name will be similar in that case function is known as constructor. constructor is special type of method because its name is similar to class name . constructor automatically calls when object will be initializing.  There are two types of constructor  1) user defined constructor  2) predefined constructor
  • 12.
  • 13.  Note:-here we have called testA() method but we didn’t call A() method because it automatically called when object is initialized.
  • 14.  PHP introduce a new functionality to define a constructor i.e __construct().  By using this function we can define a constructor. it is known as predefined constructor.  __construct() are also known as magic function in PHP.
  • 15.
  • 16.
  • 17.  <?php  class BaseClass {  function __construct()  {  echo "Shivanin";  }  }  class SubClass extends BaseClass  {  function __construct()  {  parent::__construct();  echo “sonin";  }  }  $obj = new BaseClass();  $obj = new SubClass();  ?>