Sharp Tutorial
Class object in php

Python

Java

C

C++

HTML/CSS

Java Script

PHP

SQL

C Programs

PHP Introduction

  • PHP home
  • PHP introduction
  • How to install and run
  • Syntax and Rule in PHP
  • Data type and operator
  • If else in php
  • Loop in php
  • Array in php
  • Sring in php
  • Function in php
  • Include in php

Working with Forms

  • Get and Post
  • Get Form input into PHP
  • Form Validation

PHP with MySQl

  • Connect PHP & Mysql
  • Insert using PHP Mysql
  • Select using PHP MySql
  • Delete Update using PHP Mysql
  • Login Page Example in PHP

Advanced PHP

  • Session in PHP
  • Cookies in PHP
  • File Handling in PHP
  • File Upload/Download PH

Object Oriented PHP

  • Class Obejct in PHP
  • Constructor in PHP
  • Destructor in PHP
  • Inheritance in PHP

Class object in php

As we know we can write object oriented code in php so class and objects are being created.Object oriented programming is easy to use and easy to manage.

We can create class in php as  class <classname> . Class which is the collection of similar type elements and object is the instance of class 

Class in PHP

 Syntax of the class
<?php
class <class-name>
{
// class code here
}?>

 

<?php
  class Student
   { 
    public $name="john", $age=25;// property or variable
     function display()
    {
     echo "Name=$this->name";
	 echo "<br>Age=$this->age";
    }
   }
 
   $s1= new Student(); //how object is being created of a class
   $s1->display();     //how we call the function with object name
 ?>

output of the following program is as follows.

<?php
  class Box
   { 
    public $length=0;
    public $breadth=0;
    public $area=0;

     function setValues($l,$b)
    {
        $this->length=$l;
	    $this->breadth=$b;
    }
    function calArea()
    {
     $area=$this->length*$this->breadth;
     echo "area= $area";  //this function may return the value as well
     }
   }   // end of class
   $b1= new Box();
   $b1->setValues(20,10);
   $b1->calArea();
  ?>

output of the following program is as follows.

Enquiry about Course

Ask your Question

Click Here

Sharp (2) Tutorials

Video/ C Introduction

Watch video in full size

Video tutorial

Follow by Email
Facebook
Facebook
fb-share-icon
YouTube
Copyright © Sharp Tutorial
Build with WordPress
Wordpress Social Share Plugin powered by Ultimatelysocial
Sharp Tutorial