Courses Job Ready Fresher Training AI for Class 7 to 12 Corporate Training Placements Tutorials
Free Learning Resources

IT Tutorials & Interview Prep

Free guides, interview Q&As, and job responsibility breakdowns — curated by industry veterans to help you crack MNC interviews

109+
Tutorial Articles
9
Topic Categories
100%
Free to Read
← Back to PHP

Classes

PHP Last Updated: Oct 17, 2025

Classes

Classes are the blueprint of objects. Classes hold their own data members and member functions, which can be accessed and used by creating an instance of that class. In PHP, a class is defined using the class keyword, followed by the name of the class and curly braces ({}).

Example:

<?php
class class_name {
 // code goes here...
}
?>

Creating a Class in PHP

We will create a class Employee where we will have two properties and two methods for setting and getting the property.

<?php
class Employee {
 // Properties
 public $name;
 public $surname;

 // Methods
 function set_name($name) {
   $this->name = $name;
 }
 function get_name() {
   return $this->name;
 }
}
?>

Want to practice these scenarios in a real IT environment? Our 45-Day Internship Program gives you hands-on experience with Active Directory, Ticketing Tools, and Networking.
Join the Internship →