Procedural VS Object Oriented PHP
![]() |
1. It's an old programming approach, not efficiant for current trends.
2. We devide code in functions or mixed the PHP and every where when required.
3. More Complex to debug and to provide for update features.
2. We devide code in functions or mixed the PHP and every where when required.
3. More Complex to debug and to provide for update features.
Object Oriented Approach
1. We provide our code in classes.
2. Object represent each entities.
3. Well organized code.
2. Object represent each entities.
3. Well organized code.
4. Easy to debug.
5. MVC is not without OOP concept.
5. MVC is not without OOP concept.
Role Of Object Oriented
1. Object oriented programming is a programming style in which it is customary to group all of the variables
and functions of particular topic into a single class.
2. Object oriented programming is considered to be more advanced and efficiant than the procedural style of
programming.
3. This efficiency stems from the fact that it supports better code organization,provides modularity, and reduces
the need to repeat ourselves.
4.That being said, we may still prefer the procedural style in small and simple projects. However, as our projects
grow in complexity, we are better off using the object oriented style.
and functions of particular topic into a single class.
2. Object oriented programming is considered to be more advanced and efficiant than the procedural style of
programming.
3. This efficiency stems from the fact that it supports better code organization,provides modularity, and reduces
the need to repeat ourselves.
4.That being said, we may still prefer the procedural style in small and simple projects. However, as our projects
grow in complexity, we are better off using the object oriented style.
How TO create Class :
1. In order to create a class, we group the code that handles a certain topic into one place. For Example, we can group all the code that handles the users of a blog into one class, all of the code thatis involved with the publication of the posts in the blog into a second class, and all the code that is devoted to comments into a third class.
2.To name the class, it is customary to use a singular noun that starts with a capital letter. For example, we can group a code that handles users ito a users class, the code that handles posts into a Post class, and code that is devoted to comments into a comment class.
Structure view of Class
<?php
class Car{
//The Code
}
?>
Example
class Car{
private $name,$color;
function getDetails($cN,$cC){
$this->name=$cN;
$this->color=$cC;
}
function showData(){
echo "The car is : ".$this->name."<br/>";
echo "Car Color is : ".$this->color."<br/>";
}
}
$objCar = new Car();
$objCar->getDetails("BMW","Black");
$objCar->showData();