PHP TUTORIALPHP TutorialPHP InstallationPHP Hello WorldPHP Basic SyntaxPHP CommentsPHP VariablesPHP Variable ScopePHP ConstantsPHP StringsPHP OutputPHP Data TypesPHP Type CastingPHP OperatorsPHP ConditionalsPHP Shorthand ConditionalsPHP LoopsPHP Loop Control StructuresPHP FunctionsPHP String FunctionsPHP ArraysPHP Superglobal VariablesPHP in HTMLPHP AdvancedPHP Include and RequirePHP HTTP & HTTPSPHP RegexRegex IntroductionRegex PCRE SyntaxPHP PREG FunctionsPHP FormsPHP Forms IntroductionPHP Forms CreatingPHP Forms SecurityPHP Forms ValidationPHP Forms Required InputsPHP Forms StickyPHP Forms Advanced ValidationPHP Forms FinishingPHP OOPPHP OOP IntroductionPHP OOP ClassesPHP OOP PropertiesPHP OOP ObjectsPHP OOP MethodsPHP OOP $this KeywordPHP OOP Constructors and DestructorsPHP OOP VisibilityPHP OOP InheritancePHP OOP Abstract Classes and MethodsPHP OOP InterfacesPHP OOP TraitsPHP OOP ConstantsPHP OOP StaticPHP OOP NamespacesPHP OOP Autoloading

PHP OOP Introduction

Object-Oriented Programming is the coolest thing in PHP!

What is Object-Oriented Programming?

Object-Oriented Programming, also known as OOP is a special way of programming. It is considered to be more powerful and fast for certain tasks than the normal way of programming in PHP. OOP helps you to create and manage tasks easily.

Some advantages of OOP:

  • Easy to manage
  • Easy to use
  • Prevents repetition
  • Fast and efficient

OOP is harder to understand compared to other programming techniques. But, if you understand the following 4 terms you are almost done!

  1. Class
  2. Object
  3. Properties
  4. Methods (or Functions)

In OOP, a task or topic is handled by one class.

What is a Class?

The first term we find in OOP is class. A class is a blueprint. It is a piece of code describing how to manage a topic or task in the way we want.

For instance, a class is like a blueprint of a house.

Classes in OOP PHP
Classes in OOP PHP

You can build more than one house from a blueprint. In the same way, you can create more Objects from a class.

What is an Object?

An Object is an instance of a class. It is like a house built from the blueprint. You can build more than one object from a class like creating multiple houses from a blueprint.

Objects in OOP PHP
Objects in OOP PHP

Each house can have its own color, floor tiles, home equipment and more. In the same way, different objects can have different properties.

What are Properties?

Properties are variables of an object. They are the values associated with the object. They describe the appearance of the Object.

Properties in OOP PHP
Properties in OOP PHP

Properties can be added, changed, removed. Some can also be read-only.

Color is a property of our house.

We can also perform actions on our house (like changing the color).

What are Methods?

Methods are actions that are performed on Objects. Changing the color of my house is a method performed on my house object.

Methods in OOP PHP
Methods in OOP PHP

What we learned about OOP

  • Create the blueprint (Class)
  • Create my house from the blueprint (Object)
  • Add color, width, height, floor tiles, etc. to the house (Properties)
  • Change the color when you need to change it (Methods)

About the PHP Object Oriented Programming Tutorial for Beginners

This tutorial has been written for beginners in Object-Oriented Programming. Each chapter is described with graphical illustrations and example codes. Therefore, you will understand and remember more.

Also, this tutorial is designed not only to gain your knowledge on Object-Oriented programming but also to make a sense in your mind where OOP is useful and where we should use it and not.

In the next chapters, we will learn how to use the above concepts in a practical way.

Visit PHP Help group to get some help from experts.
Profile Picture
Supun Kavinda
I'm the Founder of Hyvor, Web Developer, Physics Lover, Flutist, and a Table Tennis Player.
My Websites