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!

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) Properties and Methods Constructor Method

Luis Alveiro Martinez Botello
Luis Alveiro Martinez Botello
2,726 Points

My code is not been showed

<?php class Product { //properties public $name = 'default_name'; public $price = 0; public $desc = 'default description';

function __construct($name, $price, $desc){
    $this->name = $name;
    $this->price = $price;
    $this->desc = $desc;

public function getInfo(){
    return "Product Name: ". $this->name;//return some info about our Product.

} $p = new Product(); $shirt = new Product("Space Juice T-Shirt", 20, "Awesome Grey T-Shirt"); $soda = new Product("Space Juice Soda", 2, "Grape Flavored Thirst Mutilator");

echo $shirt->getInfo();


1 Answer

You are creating the $p, but have not provided the required variables for the constructor function.

One option is to comment out the line: $p = new Product();

Another option is to pass along the variables when you create it: $p = new Product("your product name", "your product price", "your product description");