Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Object-Oriented PHP Basics (Retired) Classes and Objects Creating a Class and Defining an Object

Creating an object that is an instance of a class

I guess I don't understand the challenge. Here's the challenge and below that is my code that is not correct.

Create an object named "bluegill" that is an instance of our Fish class.

fish.php
<?php
class Fish
{
  // Methods and functions go here
}

$obj = new Bluegill();

?>

3 Answers

Erik McClintock
Erik McClintock
45,783 Points

Timothy,

You have things set up correctly, you're just misreading the instructions a tiny bit. The second task wants you to create an object that is CALLED "bluegill", and is an instance of the class FISH.

So, where you have:

class Fish {
}

$obj = new Bluegill();

You're setting things up correctly, you've just got the wrong variable name and the wrong class name.

You want:

class Fish {
}

// name the object bluegill
// and make it a new instance of the Fish class
$bluegill = new Fish();

Erik

Thank you very much Erik. Completely understood. I appreciate you taking the time to answer my question.

class Fish{

} $blugill = new Fish();