You are on page 1of 1

Exercise: The User Class

Time to try out declaring classes and making objects for yourself.
• Create a User class
• Instantiate the class and var_dump() it

Check that the output looks as you would expect. You can run PHP from the commandline like in
the screencasts, or just output to your browser.

• Add properties for “name” and “title” of the user


• Create a method getHandle(). This should return the title, followed by the name of the
user.

Now run the following script:

<?php

$cat = new User();

$cat->title = "Sir";
$cat->name = "Fluffiness";

echo "I am " . $cat->getHandle();

Check out the example solution in exercise1-by-example.php to see one way to achieve this.

You might also like