The scopes of a property
If I wanted to define a property or method that was available to the class that created it and its children, what access scope keyword should I use?
protected
What three keywords define the access scope of a property?
protected, public, & private
What are the following symbols called “->”?
Object Operator
To access a property of an object you use the object operator which is made up which characters?
->
What best describes the $this pseudo variable?
An internal reference to the current instance of an object.
Which of the following best describes a class property?
A variable that is defined inside of a class.
<?php </p>
class Fish {
}
?>
name: “Largemouth Bass”
flavor: “Excellent”
record: “22 pounds 5 ounces”
1. 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 </p>
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 . fish. The world record weight is $this->record_weight”;
}
}
$bass = new Fish("Largemouth Bass", "Excellent", "22 pounds 5 ounces");
echo $bass-\>getinfo();?>