I am trying to change the two values, 'first' and 'last' name, using a child class. My textbook only shows how it works if there is only one variable in the main class. I have tried to expand on it and have had to just guess at how it is done when using multiple variables/values. I have tried variations on this and check it with a browser through a server.
<?php
class contactInfo {
public$first = "Robert";
public$last = "Heston";
public$address = "3289 Westmore Blvd.";
public$city = "Greensboro";
public$state = "NC";
public$zip = "27128";
/* The example in the book had the one variable which would be the same as my 'first' and it said the function had to have the same name as the class and it had equivilant of "$ft" in parenthesis and used "$this->first = $ft;" with it. I tried expanding on that and this stuff is just no good. */
function contactInfo($ft, $lt, $as, $cy, $se, $zp) {
$this->first = $ft;
$this->last = $lt;
$this->address = $as;
$this->city = $cy;
$this->state = $se;
$this->zip = $zp;
}
function showMixedInfo() {
echo "My name is ".$this->first." ".$this -> last."<br/>";
echo "I live at ".$this ->address."<br/>";
echo "and my city and state are".$this->city." ".$this->state."<br/>";
echo "and my zip code is".$this->zip."<br/>";
}
}
/* I created the child class and the variables below the only way I know how. In the book, '$newInfo = new childClass()' had the actual name change in the parenthesis, but I need to change 2 values. */
class childClass extends contactInfo {
//Maybe there needs to be some code here?
}
$newInfo = new childClass();
$this->first("Graham");
$this->last("Rouse");
$newinfo -> showMixedInfo();
?>
The instructor's "hint" used the child class like this instead and I had no more idea about how to create everything else to go with it than with what I have above:
class childClass extends contactInfo {
function showMixedInfo($ft, $lt) {
$this->first = $ft;
$this->last = $lt;
echo "My name is ".$this->first." ".$this -> last."<br/>";
echo "I live at ".$this ->address."<br/>";
echo "and my city and state are".$this->city." ".$this->state."<br/>";
echo "and my zip code is".$this->zip."<br/>";
}
}
I am at a loss with this one. This instructor gives assignments beyond the scope of the textbook then insists it's in there when no amount of rereading/studying reveals it. I have searched for solutions prior to this.