How to create an object of a class and access the class attributes in PHP
Jan 18, 2022
PHP,
1259 Views
How to create an object of a class and access the class attributes in PHP
How to create an object of a class and access the class attributes in PHP | PHP Program
We will create a class Student and then create an object of class and access all attributes of the class and then print the values attributes on the web page.
Source Code :
<?php
class Student
{
public $id;
public $name;
public $per;
}
$S = new Student();
$S->id = 500;
$S->name = "Suman Kumar";
$S->per = 91.28;
print ("Student Id is : " . $S->id . '<br>');
print ("Student Name is : " . $S->name . '<br>');
print ("Student Percentage is : " . $S->per . '<br>');
?>