oop php w3 code example
Example: object oriented programming php
<?php
class Parent {
public function __construct() {
echo "Parent Created\n";
}
public function sayHello() {
echo "Hello, from Parent\n";
}
public function eitherHello() {
echo "Hello, from Parent and child if desired\n";
}
}
class Child extends Parent {
public function __construct() {
echo "Child Created\n";
}
public function sayHello() {
echo "Hello, from Child\n";
}
}
$p = new Parent();
$c = new Child();
$p->sayHello();
$c->sayHello();
$p->eitherHello();
$c->eitherHello();
?>