Object-Oriented Programming in PHP
PHP supports object-oriented programming (OOP) concepts such as classes, objects, inheritance, and polymorphism. OOP allows developers to write reusable and modular code.
Example:
class Person {
public $name;
public $age;
function __construct($name, $age) {
$this->name = $name;
$this->age = $age;
}
function introduce() {
echo "My name is " . $this->name . " and I am " . $this->age . " years old.";
}
}
$person1 = new Person("John", 30);
$person1->introduce();
No comments:
Post a Comment