Objects in PHP
Building Your First Class

Great, now you know the technical terms. :-)
Let's start coding by reconstructing the Person class.

The basic class syntax looks like the following:

class Classname {


The class keyword means that you create a new class; the syntax is quite similar to the function syntax.

And you can create new instances of this class using the following syntax:

$obj1 = new Classname();

The new keyword means that you create a new object and ensures that your arguments are added as properties, so it initializes the constructor (which we are going to deal with later).

We don't need to pass in any arguments, as we haven't added any properties (which can store different values depending on the instance) quite yet.

  1. Add a pair of<?php ?> tags in line 9.
  2. Create a Person class.
  3. Create two instances of the Person class: $teacher and $student.
Stuck? Get a hint! Hint
Get live, fast support from Codecademy Advisors when you get stuck. Learn more.

The needed syntax in one block:

  class Classname {

  $obj1 = new Classname();
  $obj2 = new Classname();

Remember, you mustn't pass in any arguments this time, as your class doesn't have any properties yet!

View Preview