How to Write Class in OOP PHP ?

This instructional exercise, we will begin from the essential idea of classes . Class is something which characterizes your article. Class speaks to all properties and practices of item. Presently give us a chance to take a sample of the programming. Your advantage adding machine article is case of class interest adding machine. Interest adding machine class characterizes properties like capital rate, and conduct like basic interest count and self multiplying dividends estimation.

In PHP making of class is extremely basic. You can make class utilizing label class. In class piece you can characterize your properties as class variable and capacity as class conduct. Classes and Objects are key a portion of item situated programming


class MyClass 
        public $var;

    // Class constructor
    public function __construct($var)
        echo 'Created an object of MyClass';
        $this->var = $var;

    public function show_var()
        echo $this->var;
// Make an object
$objA = new MyClass('A');

// Call an object method to show the object's property

// Make another object and do the same
$objB = new MyClass('B');

Read more OOP in PHP

I hope its helpful for every one, contact & ask any question on

Published by

Smart Web Care

Smart Web Care offers a wide range of IT Solutions ranging from Website Development, E-Commerce Solutions, Multimedia, Brand Promotions, Graphic design, Domain Registration, Android/iOS App developer,Web Designer, Software Application Company, Web hosting company, IT support and services, Internet Marketing Service, Marketing Consultant Servers, Web Hosting and Tanning provider.