Oops Concepts in PHP For Beginners

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.

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Article Tags: , ,