php8.5
Home/ Manual/ language/ Classes and Objects

Classes and Objects

PHP includes a complete object model. Some of its features are: visibility, abstract and final classes and methods, additional magic methods, interfaces, and cloning.

Introduction

PHP includes a complete object model. Some of its features are: visibility, abstract and final classes and methods, additional magic methods, interfaces, and cloning.

PHP treats objects in the same way as references or handles, meaning that each variable contains an object reference rather than a copy of the entire object. See Objects and References

Userlandnaming

Basic Properties Property-hooks Constants Autoload Decon Visibility Inheritance Paamayim-nekudotayim Static Abstract Interfaces Traits Anonymous Overloading Iterations Magic Final Cloning Object-comparison Late-static-bindings References Serialization Variance Lazy-objects Changelog

In this section

Anonymous classes

Anonymous classes are useful when simple, one-off objects need to be created.

Autoloading Classes

Many developers writing object-oriented applications create one PHP source file per class...

Class Abstraction

PHP has abstract classes, methods, and properties. Classes defined as abstract cannot be i...

Class Constants

It is possible to define constants on a per-class basis. The default visibility of class c...

Comparing Objects

When using the comparison operator (==), object variables are compared in a simple manner,...

Constructors and Destructors

PHP allows developers to declare constructor methods for classes. Classes which have a con...

Covariance and Contravariance

In PHP 7.2.0, partial contravariance was introduced by removing type restrictions on param...

Final Keyword

The final keyword prevents child classes from overriding a method, property, or constant b...

Late Static Bindings

PHP implements a feature called late static bindings which can be used to reference the ca...

Lazy Objects

A lazy object is an object whose initialization is deferred until its state is observed or...

Magic Methods

Magic methods are special methods which override PHP's default action when certain actions...

OOP Changelog

Changes to the PHP OOP model are logged here. Descriptions and other notes regarding these...

Object Cloning

Creating a copy of an object with fully replicated properties is not always the wanted beh...

Object Inheritance

Inheritance is a well-established programming principle, and PHP makes use of this princip...

Object Interfaces

Object interfaces allow you to create code which specifies which methods and properties a...

Object Iteration

PHP provides a way for objects to be defined so it is possible to iterate through a list o...

Objects and references

One of the key-points of PHP OOP that is often mentioned is that "objects are passed by re...

Overloading

Overloading in PHP provides means to dynamically create properties and methods. These dyna...

Properties

Class member variables are called properties. They may be referred to using other terms su...

Property Hooks

Property hooks, also known as "property accessors" in some other languages, are a way to i...

Scope Resolution Operator (::)

The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the...

Serializing objects - objects in sessions

serialize returns a string containing a byte-stream representation of any value that can b...

Static Keyword

Declaring class properties or methods as static makes them accessible without needing an i...

The Basics

Basic class definitions begin with the keyword class, followed by a class name, followed b...

Traits

PHP implements a way to reuse code called Traits.

Visibility

The visibility of a property, a method or (as of PHP 7.1.0) a constant can be defined by p...

Source: language/oop5.xml · from the official PHP manual (php/doc-en)