-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructorAndDestructor.php
More file actions
39 lines (37 loc) · 1.02 KB
/
constructorAndDestructor.php
File metadata and controls
39 lines (37 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
class student{
var $id;
var $name;
var $faculty;
var $program;
var $semester;
//constructor creation
function __construct($id,$name,$faculty,$program,$semester){
$this->id=$id;
$this->name=$name;
$this->faculty=$faculty;
$this->program=$program;
$this->semester=$semester;
echo "<br> object created: ".$name."<br>";
}
//destructor creation, use this function while using unset inorder to show object has been destroyed
// function __destruct(){
// echo "<br> object destroyed: ".$this->name."<br>";
// }
function print(){
echo "<hr>";
echo "student id:".$this->id."<br>";
echo "student name:".$this->name."<br>";
echo "student faculty:".$this->faculty."<br>";
echo "student program:".$this->program."<br>";
echo "student semester:".$this->semester."<br>";
}
}
//for constructor
$student1= new student(1,"Greesma","management","BIM","fourth");
$student1->print();
$student2= new student(2,"Asmita","science","BSCCSIT","fourth");
$student2->print();
// to destroy object use
unset($student2);
?>