CONCEPTS OF CLASS AND OBJECTS IN PHP ALONG WITH MY OWN GIVEN REAL LIFE EXAMPLES
CONCEPTS OF CLASS AND OBJECTS IN PHP ALONG WITH MY OWN GIVEN REAL LIFE EXAMPLES
Hi all, a very good morning. Today I am going to explain about the concepts of class and objects along with some real real life examples. So, without wasting time, let's begin with the explanation.
So, first of all let's discuss about the concepts of class. So, guy's what is class?
Class is a container, which contains group of variables, functions and other class objects. We can also say that class is the blueprint of objects. Now coming to some real life examples of class. So, some real life examples of class are like school class, college class, tuition class, etc. and I think no other real life examples of class can be as best as the above real life examples.
Now, let's discuss about the concepts of object. So, guy's what is object?
Object is the instance of a class. Now coming to some real life examples of object. So, some real life examples of object are like table, chair, desktop, laptop, we the human beings, etc this are all real life examples of objects. And I think no other real life examples of object can be as best as the above real life examples.
Like if within a class their is function, we can't call the class directly, object is used to define to call the class as $obj as because object is the instance of a class.
For example =>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Registration Form</title>
<style type="text/css">
.c1{
background-color: lightcoral;
color: azure;
text-align: center;
font-size: 40px;
}
.c2{
text-align: center;
}
.c3{
text-align: center;
background-color: burlywood;
color: rebeccapurple;
font-weight: bolder;
}
.c4{
background-color: aliceblue;
color: chocolate;
font-weight: bolder;
font-size: 20px;
}
</style>
</head>
<body>
<h3 class="c1">Simple Registration Form</h3>
<div class="c2">
<img src="https://media.istockphoto.com/id/1463013729/photo/online-registration-form-for-modish-form-filling.jpg?s=612x612&w=0&k=20&c=Fnx06haU4IHYLcRpy9Po_TBknvBqVjicGuUWkGu8e6Y=" height="250px" width="250px">
</div>
<form class="c3">
<fieldset>
Type: <input type="radio" name="type" value="personal">Personal
<input type="radio" name="type" value="company">Company<br>
Email: <input type="email" name="email"><br>
Name: <input type="text" name="name"><br>
Password: <input type="password" name="password"><br>
Gender: <input type="radio" name="gender" value="male">Male
<input type="radio" name="gender" value="female">Female<br>
<button type="submit" name="submit" value="submit" class="c4">Submit</button>
</fieldset>
</form>
<?php
if (isset($_REQUEST['submit'])) {
$Type=$_REQUEST['type'];
$Email=$_REQUEST['email'];
$Name=$_REQUEST['name'];
$Password=$_REQUEST['password'];
$Gender=$_REQUEST['gender'];
class RegistrationForm
{
function __construct($Type,$Email,$Name,$Password,$Gender)
{
$this->ty=$Type;
$this->em=$Email;
$this->na=$Name;
$this->pa=$Password;
$this->ge=$Gender;
}
function display()
{
echo $this->ty."<br>".$this->em."<br>".$this->na."<br>".$this->pa."<br>".$this->ge;
}
}
$obj=new RegistrationForm($Type,$Email,$Name,$Password,$Gender);
$obj->display();
}
?>
</body>
</html>
Comments
Post a Comment