3. NuevoThoughts Technologies
www.NuevoThoughts.com
What is OOP?:
Object Oriented Programming-
Basically means Programming driven by Object
Object Oriented
Programming
Procedural Programming
Programming Languages
Code controlling data
(Code is important)
Data is to Access code
(Data is important)
4. NuevoThoughts Technologies
www.NuevoThoughts.com
Object Oriented Programming:
Class: Programmer defined datatype include function & variables.
Object: Individual instances , used to access variable & method.
Functions: Set of code (specific tasks).
Variables: Data
Inheritance
Class in class(parent & child class)
Polymorphism
Overloading
Abstraction
Encapsulation
Constructor
Destructor
5. NuevoThoughts Technologies
www.NuevoThoughts.com
Why do we use OOP in PHP:
We can use PHP both as procedural and Object oriented language.
Now, question is why we use OOP concept in PHP?:
Reasons:
Flexibility
Reduce source code by more than 99.9%.
Much easier in implementing security.
Makes coding more organized.
Help to work in team easily.
6. NuevoThoughts Technologies
www.NuevoThoughts.com
Flexibility:
Easily extend our PHP code whenever we require.
Member variables & functions are easily accessible from any where in the code.
Example:
in abc.php:
class sample
{
public $var;
function sample-f()
{
some code………
}
}
in abc1.php:
<?php include abc.php
$obj=new sample();
$obj->var=738
$obj->sample-f();?>
7. NuevoThoughts Technologies
www.NuevoThoughts.com
Reduce Source Code by more than 99.9%:
When we create big project which require lots of files, it reduces our lots of work.
In procedural PHP when we require same variable in more than one file, we copy
paste that variable or function .
But in case of OOP PHP we just put code in class , by object we can call them.
Example: in abc.php
class s1
{
public $var;
function f1()
{
//code}
}
*in abc1.php *in abc2.php
<?php include ‘abc.php’; <?php include ‘abc.php’;
$obj=new s1();
$obj->var=“hello”;?> $obj=new s1();
$obj->var=“hi”; ?>
8. NuevoThoughts Technologies
www.NuevoThoughts.com
Much easier in implementing security:
Security is most vital requirement in web development.
OOPs provide security by using object, all data transferred in terms of objects.
Example:
In abc.php in abc1.php
Class a <?php
{$var; include ‘abc.php’;
public Function f1($val) $obj=new a();
{If($val==NULL) $obj->f1(“sss”);
{ echo $obj->val;
This->val=“hello1”; //$obj->f2(“123”);
}} //echo $obj->val;
Public Function f2($val) ?>
{if($val==123)
This->val=“hello2”;
}}
10. NuevoThoughts Technologies
www.NuevoThoughts.com
How do we use OOP in PHP?:
Step 1: Create two or more PHP files:(assuming two)
Index.php
Class.php
Step 2: Put all OOP code in class.php;
Class a()
{
$var;
Function f($val)
{
this->var=$val;
}
}
Step 3:create object and access OOP functions/variables from another file.
<?php
Include class.php;
$obj=new a();
$obj->var=“hi”;
$obj->f(“hello”);
?>
12. NuevoThoughts Technologies
www.NuevoThoughts.com
Model:
A model is an object representing data or even activity.
The model manages the behavior and data of the application domain.
The model is the piece that represents the state.
View:
A view is some form of visualisation of the state of the model.
The view is responsible for mapping graphics onto a device.
Controllers:
A controller offers facilities to change the state of the model.
A controller is the means by which the user interacts with the application.