Intro to OO PHP

Intro to OO PHP

To learn how to write Object Oriented PHP, we will start with some basics and build upon those. I will use fictitious and realistic examples. We will also use a simple autoloader, so we don’t have to use includes for each file.

Autoloading


<?php
/**
* autoload.php
*/
function __autoload($class_name) {
	require_once("./src/$class_name.php");
}

Eventually, you will want to use composer to install packages and to generate your autoloader.

Classes

Interfaces

Abstract Classes

Traits

Polymorphism

Namespaces