TOC

The community is working on translating this tutorial into Portuguese, but it seems that no one has started the translation process for this article yet. If you can help us, then please click "More info".

Classes:

Introduction to PHP classes

While classes and the entire concept of Object Oriented Programming (OOP) is the basis of lots of modern programming languages, PHP was built on the principles of functions instead. Basic support for classes was first introduced in version 4 of PHP but then re-written for version 5, for a more complete OOP support. Today, PHP is definitely usable for working with classes, and while the PHP library still mainly consists of functions, classes are now being added for various purposes. However, the main purpose is of course to write and use your own classes, which is what we will look into during the next chapters.

Classes can be considered as a collection of methods, variables and constants. They often reflect a real-world thing, like a Car class or a Fruit class. You declare a class only once, but you can instantiate as many versions of it as can be contained in memory. An instance of a class is usually referred to as an object.

If you're still a bit confused about what classes are and why you need them, don't worry. In the next chapter, we will write our very first class and use it. Hopefully that will give you a better idea of the entire concept.


This article has been fully translated into the following languages: Is your preferred language not on the list? Click here to help us translate this article into your language!