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 trialMUZ140045 Tafadzwa Gumunyu
13,202 Pointsstage 2 challenge 1
Add the following public properties to the Fish class: common_name, flavor, and record_weight.
<?php
class Fish {
$p-> name = ("common_name"."flavor"."record_weight");
}
?>
2 Answers
Logan R
22,989 PointsYou create a public variable by doing:
public $variable_name;
So in this case, it would be:
class Fish {
public $common_name;
public $flavor;
public $record_weight;
}
When you want the property, like how you did, you do the following outside of the class:
$fish = new Fish();
$fish->common_name = "Fish";
Kristi Smythe
10,665 PointsHi Taf (pls forgive if this short name isn't ok ;)
The clues in this challenge are 'public' (the encapsulation access definition) and 'properties' (variables). So we are setting up our variables (properties) like so:
class Fish {
public $property(first variable name)
public $property(second variable name)
public $property(third variable name)
}
Defining these properties as public in our Fish class will enable us to utilize them for any object of fish that we instantiate (create) for different species of fish.
I'm also in always learning mode, so I hope this helps.
Cheers, Kristi