An object is created (/ instantiated) using the keyword new to assign the class to the user defined object name.

e.g. $myObject = new className ;


This example uses the var_export() function to view the contents of the object:


class Bike {}

echo "<h1>Instantiating a Bike object</h1><br>" ;

$myObject = new Bike ;

echo "<pre>" . var_export($myObject, TRUE) . "</pre>" ;


Save & refresh browser:

Instantiating a Bike Object



The var_export() function is showing a NULL output since the class is empty (i.e. it has no members; properties/methods).

Leave a Reply