PHP Class

What is Class in PHP?

A class is a collection of variables and functions working with these variables. Variables are defined by var and functions by function.

Syntax of PHP Class

Basic class definitions begin with the keyword class, followed by a class name, followed by a pair of curly braces which enclose the definitions of the properties and methods belonging to the class.

A class is defined using the following syntax:

<?php
class Student
{
    // property declaration
    public $var = 'value123';

    // method declaration
    public function display() {
        echo $this->var;
    }
}
$s1=new Student();
$s1->display();
?>
Tutorials Class - Output Window

value123


Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.