What is DevRel? | What is Developer Relations ?
A to Z Full Forms and Acronyms

How to create an object of a class and access the class attributes in PHP

Jun 24, 2021 PHP, 404 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>');
?>
A to Z Full Forms and Acronyms
Nitin Pandit

Nitin Pandit

With over 10 years of vast development experience with different technologies, Nitin Pandit is Microsoft certified Most Valued Professional (Microsoft MVP) with a rich skillset that includes developing and managing IT/Web-based applications in different technologies, such as – C#.NET, ADO.NET, LINQ to SQL, WCF, and ASP.NET 2.0/3.x/4.0, WCF, WPF, MVC 5.0 (Razor), and Silverlight, along with client-side programming techniques, like jQuery and AngularJS. Nitin possesses a Master’s degree in Computer Science and has been actively contributing to the development community for its betterment. He has written more than 100 blogs/articles and 3 eBooks on different technologies to help improve the knowledge of young technology professionals. He has trained more than one lakh students and professionals, as a speaker in workshops and AppFests, conducted in more than 25 universities in North India.

Related Article

Cookies.

By using this website, you automatically accept that we use cookies. What for?

Understood