php Creating an Object

It’s much easier to create objects and use them than it is to define object classes, to create an object of a given class, use the new keyword:

$object = new Class;

Assuming that a Person class has been defined, here’s how to create a Person object:

$rasmus = new Person;

Some classes permit you to pass arguments to the new call. The class’s documentation should say whether it accepts arguments. If it does, you’ll create objects like this:

$object = new Person(“Fred”, 35);

Leave a Comment