Blog Introductions
In this blog contains tutorials about HTML Tutorials, Python Tutorials, CSS Tutorials, How to, PHP Tutorials, Java Tutorials, C++ Tutorials, Tutorials, Examples, Source code,Learning,
Tips and Software development services. Php Oop Object Orriented Programing | Php tutorials Bestitworriors
Php Oop Object Orriented Programing
Php Oop Object Orriented Programing | Php tutorials Bestitworriors - OOP stands for object-orriented Programing.In oop we create classes which contain variables and function.oop is easier and help us to write clean code.oop is easily to reuse again again classes for multipule function and work.oop is easy to exicute on server.Object define as which have some properties and function e.g car is a object which have properties color,structure ,size and functon is drive ,stop etc.OOP takes less time to code and development process rather then procdural code.
Some Key Points of PHP OOP
- OOP stands for object orriented programin
- In oop we study and work about object
- Object which have some properties and functions
- we create class for working on object
- Class have constructor
- Class have Access Modifiers
- public property or method can be accessed from everywhere
- protected property or method can be accessed within the class and by classes derived from that class
- private - the property or method accessed within the class
- Class have Inheritance
- Class have Constants
- Class have static Methods
- Class have static properties
Code
<?php
class Month {
public $month;
public $year;
public function __construct($month, $year) {
$this->month = $month;
$this->year = $year;
}
public function intro() {
echo "<br>";
echo "The Month is {$this->month} and the Year is {$this->year}.";
}
function __destruct() {
echo "<br>";
echo "The month is {$this->month}.";
}
}
// Strawberry is inherited from Fruit
class Years extends Month {
public function message() {
echo "<br>";
echo "I am year Class ";
}
}
$object = new Years(12, 2022);
$object->message();
$object->intro();
?>
OutPut
I am year Class
The Month is 12 and the Year is 2022.
The month is 12.
The Month is 12 and the Year is 2022.
The month is 12.
0 Comments