What is a Class in PHP?

What is a Class in PHP?

In simple words, class is a user defined datatype. Which have its own constants, variables and functions. The variables of a Class are called properties of the Class and Functions of the Class are called  methods of the Class.

Naming Convention

Name of the class can be anything provided that it must be a combination of letters, underscores and numbers. It must start with a letter and underscore.

How it looks like:

# Example:


class SoorajExampleClass


// properties or variables declaration

public $var1   = “this is public variable1”;

private $var2 = ‘this is private variable 2’;


// functions or methods declaration

public function bring1()


echo $this->var1;





Share this post

Leave a Reply

Select Your Currency