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 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 Object Oriented ProgrammingPHP 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 Interfaces

PHP OOP Classes

Classes are blueprints.

Class Declaration in PHP

A class wraps a code that handles a specific task or topic. In this tutorial set, we will create classes and objects for houses as examples. So, the class is your blueprint. You can use this blueprint to create different houses. But, all of them will have the same properties (with different values) and the same methods.

Let's create a class named House.


<?php
class House {
	// code
}

Here, class is the keyword to say that you are going to write a class. House is the name of your class.

All the code of the class will be written inside the braces. In this way, you can wrap all the data and functions of a task inside one class. For instance, in our house class, we can save data like color and functions like change color in the class.

Naming a Class

* Best Practices for Naming Classes

Facebook Twitter