PHP - Classes and objects

Introduction

A class is defined by the keyword class followed by a valid class name.

To create an object, use the keyword new followed by the name of the class.

We assign the instance to a variable:

<?php 

     class Book { 
     } 

     class Customer { 
     } 

     $book = new Book(); 
     $customer = new Customer(); 
?>

You can create many instances, as long as you assign them to different variables:

$book1 = new Book(); 
$book2 = new Book(); 

Related Topics

Exercise