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 trialMaxwell Kendall
Front End Web Development Techdegree Student 12,102 PointsOO PHP Task 2
Cannot figure out how I am using the Construct method wrong...?
<?php
class Fish {
public $common_name;
public $flavor;
public $record_weight;
}
function __construct($name, $flavor, $record){
$this-> common_name = $name;
$this-> flavor = $flavor;
$this-> record_weight = $record;
}
?>
4 Answers
Craig Watson
27,930 PointsHi,
I think your are pretty much there other than a extra } you have and spaces on the $this->property_name areas of the __construct.
So from your above code it should be like this :
<?php
class Fish
{
public $common_name;
public $flavor;
public $record_weight;
function __construct($name, $flavor, $record){
$this->common_name = $name;
$this->flavor = $flavor;
$this->record_weight = $record;
}
?>
Hope this helps, it has been a while since I did a little php :) Craig
Maxwell Kendall
Front End Web Development Techdegree Student 12,102 PointsLooks like it's still not passing! Thank you for your help, though!
Maxwell Kendall
Front End Web Development Techdegree Student 12,102 PointsLooks like it's still not passing! Thank you for your help, though!
Craig Watson
27,930 PointsSorry,
I have had a go of the challenge and this has passed :)
<?php
class Fish {
public $common_name;
public $flavor;
public $record_weight;
function __construct($name, $flavor, $record){
$this->common_name = $name;
$this->flavor = $flavor;
$this->record_weight = $record;
}
public function getInfo(){
// using concatination you can call the defined method objects
return "A" . $this->common_name . " is an " . $this->flavor . " fish. The world record weight is " . $this->record_weight;
}
}
$bass = new Fish("Largemouth Bass", "Excellent", "22 pounds 5 ounces");
?>
Craig
Mirte Mulder
2,217 PointsMuch appreciated!