Oops Concepts in PHP For Beginners

Prem Tiwari - - PHP Tutorial

Classes Structure

A Class is a blueprint of an object information. It defines the variables and methods that gives a collection of information. For example, lets just see some examples to know the structure of the class :

Create object of class

An Object is a actual thing that create bases of a blueprint (class).

Properties of an object :

  • Identity: the property of an object that distinguishes it from other objects
  • State: describes the data stored in the object
  • Behavior: describes the methods in the object’s interface by which the object can be used

Bellow is the complete code that define a class and and an object.

Copy and paste that code and save as test.php and reloading your browser now you get the outputs the following:

Hello world!

Using of Constructors and Destructors

PHP provides the magic method__construct() which called when you create an object of a class.

Prem Tiwari

Prem Tiwari is the founder of FreeWebMentor.com and also a professional developer and a blogger by hobby.

Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.