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) Inheritance, Interfaces, and Exceptions Object Inheritance

Mohamed Roshdy
Mohamed Roshdy
2,437 Points

i have code error

hi i wrote this and i get blank screen there is no results

<?php

class Product {

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;

}

}

class Soda extends Product {

public $flavor;

function construct($name, $price, $desc,, $flavor){ parent::construct($name, $price, $desc); $this->flavor = $flavor }

public function getInfo(){ return "Product Name: ". $this->name . " Flavor: ". $this->flavor; }

}

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

echo $soda->getInfo();

?>

1 Answer

Josh Cummings
Josh Cummings
16,310 Points

Hi Mohamed,

Looks like you had a couple of syntax errors on lines 24, 25, and 26 of your code.

You left off the two underlines when using the construct keyword, and had two commas after $desc instead of one.

You also had a missing semicolon after $this->flavor = $flavor.

Those lines should look like this:

function __construct($name, $price, $desc, $flavor){
  parent::__construct($name, $price, $desc);
  $this->flavor = $flavor;
}

Hope this helps.

Mohamed Roshdy
Mohamed Roshdy
2,437 Points

thanks josh ,, now its work fine