Professional Documents
Culture Documents
Exp 8 PHP
Exp 8 PHP
Exp 8 PHP
Roll No : 210418
Practical No : 8
1. Write a program for array of objects
<?php
class student{
public $name,$age;
public function __construct($name,$age){
$this->name = $name;
$this->age = $age;
}
public function intro(){
echo "Name : $this->name <br>";
echo "Age : $this->age <br>";
}
}
$std1 = new student("Hassaan",18);
$std2 = new student("Azlan",18);
$std3 = new student("Mohiuddin",18);
$arr = array($std1,$std2,$std3);
foreach($arr as $i){
$i->intro();
}
?>
<?php
class Addition{
function __call($nof , $args){
if($nof == 'Add'){
switch(count($args)){
case 1 :
return $args[0];
break;
case 2 :
return $args[0] + $args[1];
break;
case 3 :
return $args[0] + $args[1] + $args[2];
break;
}
}
}
}
$a = new Addition();
echo $a->Add(2,3)."<br>";
echo $a->Add(2,3,4)."<br>";
echo $a->Add(2);
?>
?>
4. Write a program for single level inheritance
<?php
class parentClass{
public $name;
public $age;
function getData($name,$age){
$this->name = $name;
$this->age= $age;
}
}
class childClass extends parentClass{
function display(){
echo "name: $this->name <br> age: $this->age";
}
}
$c = new childClass();
$c->getData("Abu Hassaan","18");
$c->display();
?>
}
$obj = new Student("Abu Hassaan ",1318);
?>
}
class child1 extends Base{
?>
}
class children extends Base{
function printdata(){
echo "Overriden function";
}
}
$obj = new children();
$obj-printdata();
?>
?>
13. Write a program for static keyword with respect to function and properties
<?php
class root{
public static $c;
function display2(){
self::display1();
echo "My name is Abdul Hassaan<br>";
}
}
$obj1->count();
$obj1->count();
?>