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
Chris Howell
Python Web Development Techdegree Graduate 49,703 PointsObject-Oriented PHP Basics
Just completed the PHP OOP Basics series. Hampton Paulk, you did a great job in these videos, I enjoyed it and learned quite a bit from it. I know making the videos take a good deal of time, but I can't tell you how long I have been waiting to see some OOP PHP done by treehouse.
I can't wait until you get more videos up to scratch the surface even more and maybe even start doing light surgery on this topic.
Thank you good sir.
5 Answers
Hampton Paulk
5,093 PointsThanks Chris! Lots more to come, I am just getting started.
Elijah Collins
19,457 PointsThis worked for me
<?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() {
return "A " . $this->common_name . " is an " . $this->flavor .
" flavored fish. The world record weight is " . $this->record_weight;
}
}
$bass = new Fish('Largemouth Bass', 'Excellent', '22 pounds 5 ounces');
echo $bass->getInfo();
?>
Colin Marshall
32,861 PointsJust finished this one as well and thought you did a great job Hampton. Looking forward to more! Any ETA on the next course or can you tell us what the topic will be? Thanks!
davpay
40,173 PointsAny chance of a hand, I have got completely lost with this!
Create a method on Fish named getInfo that takes no parameters and returns a string that includes the common_name, flavor, and record_weight for the fish. When called on $bass, getInfo might return "A Largemouth Bass is an Excellent flavored fish. The world record weight is 22 pounds 5 ounces."
<?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() {
return "A", $this->common_name, "is an", $this->flavor, "flavored fish. The world record weight is", $this->record_weight;
}
}
$bass = new Fish("Largemouth Bass", "Excellent", "22 pounds 5 ounces");
echo $bass->getInfo();
?>
Probably completely wrong haha!
Hampton Paulk
5,093 PointsString concatenation is with a "." and not a ","
davpay
40,173 PointsThanks Hampton - I cannot believe I made that stupid mistake! That's what happens when you're staring at the same problem for 2 hours+ I guess - it all looks the same! So close, but yet so far...
Hampton Paulk
5,093 Pointsdon't even worry about it. It happens to everyone, on every level.