Module Development
Topic

Object-Oriented PHP for Drupal 8, 9, 10, and 11

Object-oriented PHP utilizes classes and objects to organize code into reusable chunks. This approach helps us organize complex applications, such as Drupal, into modular code called classes that can be reused across the entire system. As a module developer, knowledge of object-oriented PHP is essential in order to understand the architecture of a module and the various forms it can take as well as how to implement custom functionality.

Example tasks

Confidence

Learning modern object-oriented PHP practices is a skill that will benefit you not only as a Drupal developer but also as a PHP developer. If you have a doubt about a certain feature working on your project, check php.net to see which versions of PHP are supported. Also, verify your version of PHP on your localhost as well as your web host.

Drupalize.Me resources

Posted on Tuesday, August 12, 2014 - 09:00 by joe
As a developer, one of the first new concepts you're going to need to understand for Drupal 8 is PSR-4. Or, the PHP Framework Interoperability Groups (php-fig), Proposal for Standard Request number 4 (PSR-4). A lot of fancy naming, abbreviations and numbers for a pretty simple idea. Allow your PHP classes to be automatically discovered and loaded by following a convention for class namespace and file/directory naming.
Categories
Drupal 8, 9, 10, and 11
More information

Annotations are specially-formatted PHP docblock comments that are used for class discovery and metadata description. While it is technically possible to use annotations for other purposes, at the moment Drupal only uses them for the plugin system.

In this tutorial we'll look at:

  • What annotations are
  • The use case for annotations
  • How to figure out what you can put into an annotation

By the end of this tutorial you should understand how annotations are used in Drupal and how to write them in your own code.

Categories
Drupal 8, 9, 10, and 11
More information

Dependency injection is a design pattern commonly used in object-oriented software architectures in order to support Inversion of Control.

PHP

Topic
Drupal 7, 8, 9, and 10
More information

PHP: Hypertext Preprocessor (PHP) is a popular interpreted programming language that is especially suited for web development. Drupal core and all contributed modules are written in PHP.

More information

Drupal core uses object-oriented programming (OOP). This method of programming introduces new coding standards to the project. In this tutorial we'll cover the Drupal coding standards that relate to object-oriented PHP code.

By the end of this tutorial you should know how to implement the Drupal coding standards related to OOP, and where to find more information when you've got questions about the standards.

Services

Topic
Categories
Drupal 8, 9, 10, and 11
More information

Services are objects that encapsulate the code for performing specific tasks in a reusable and decoupled way.

Related guides

Categories
Module Development, Backend and Infrastructure
Drupal 8, 9, 10, and 11
Categories
Site Building, Theming, Module Development
Drupal 9, 10
Categories
Module Development, Backend and Infrastructure
Drupal 9, 10

Guides

Not sure where to start? Our guides provide useful learning tracks for all skill levels.

Navigate guides

External resources