$object = new Class;
Assuming that a Person class has been defined,
here's how to create a Person
object:
$rasmus = new Person;
Do not quote the class name, or you'll get a
compilation error:
$rasmus = new 'Person'; // does not work
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);
The class name does not have to be hardcoded into your program. You
can supply the class name through a variable:
$class = 'Person';
$object = new $class;
// is equivalent to
$object = new Person;
Specifying a class that doesn't exist causes a
runtime error.