Wednesday 30 September 2020

How to Create Simple Class using PHP

What is Class in PHP

  • class is a container that can contain variables, constructors, functions etc.
  • This is a programmer-defined data type, which includes local functions as well as local data.
  • A class is a self-contained, independent collection of variables and functions which work together to perform one or more specific tasks, while objects are individual instances of a class.

Syntax:

class classname
{
variables
function functionname
{
--
}

}

class object
calling function
display function

Example: 

<?php
class student
{
//var $rollno;
//var $name;
function get()
{
$this->rollno = 10;
$this->name = 'raj';
}
function display()
{
echo "<pre><br>Roll No : " . $this->rollno;
echo "<br>Name : " . $this->name;
}
};
$obj = new student();
$obj->get();
$obj->display();
?>


Learn all the programming inside youtube.com/avadhtutor





No comments:

Post a Comment