The PHP Object-Oriented Programming concepts are:
Class
Objects
Inheritance
Interface
Abstraction
Magic Methods
Andomi Ansari
<?php
class Parent {
public function __construct() {
echo "Parent Created
";
}
public function sayHello() {
echo "Hello, from Parent
";
}
public function eitherHello() {
echo "Hello, from Parent and child if desired
";
}
}
class Child extends Parent {
public function __construct() {
echo "Child Created
";
}
public function sayHello() {
echo "Hello, from Child
";
}
}
$p = new Parent(); // Parent Created
$c = new Child(); // Child Created
$p->sayHello(); // Hello, from Parent
$c->sayHello(); // Hello, from Child
$p->eitherHello(); // Hello, from Parent and child if desired
$c->eitherHello(); // Hello, from Parent and child if desired
?>
<?php
class My{
public $name,$age;
public function __construct($myName,$myAge)
{
$this->name = $myName;
$this->age = $myAge;
}
}
$me = new My("WinWinMaw",22);
//$me->name = "hhz";
//$me->age = 22;
$my = new My("Maw",20);
//$me->name = "hhz";
//$me->age = 22;
$abc = new My("abc",32);
print_r([$me,$my,$abc]);
?>
//run => php filename.php
use auth