Class in php with __contruct magic function()
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>oops in php by saddam</title>
</head>
<body>
creat many object in one class
<?php
class student
{
public $name, $age, $clss,$address;
function __construct($n,$a,$c,$ad)
{
$this->name=$n;
$this->age=$a;
$this->clss=$c;
$this->address=$ad;
}
}
echo "</br>";
$obj1=new student('saddam','17','15','delhi');
echo $obj1->name ."</br>";
$obj2=new student('sanjay','17','15','rudarpur');
echo $obj2->name ."</br>";
$obj3=new student('hitesh','17','15','darghat');
echo $obj3->name ."</br>";
$obj4=new student('vikass','17','15','delhi');
echo $obj4->name ."</br>";
?><br />
output:- should be like this :-
saddam
sanjay
hitesh
vikass
</body>
</html>
Comments
Post a Comment