I have just started learning some PHP. I have alot of experience with c/c++ and java, but wanted to learn about this "php thing" i keep hearing about.
I'm trying to create an object which has five values in it. However, I must be doing something wrong syntactically becaue the output isn't what I expect. Either I am assigning the variables incorrectly in the constructor, or I am not displaying them correctly, because my output isn't what I expect.
The class definition:
Code: Select all
class record
{
var $name;
var $score;
var $hits;
var $shots;
var $date;
function record($newName, $newScore, $newHits, $newShots, $newDate)
{
$this->$name = $newName;
$this->$score = $newScore;
$this->$hits = $newHits;
$this->$shots = $newShots;
$this->$date = $newDate;
}
function recordEcho()
{
echo "RECORD=" . $this->$name . " " . $this->$score . " " . $this->$hits . " " . $this->$shots . " " . $this->$date . "<br>";
}
}Code: Select all
echo "NAME = " . $submittedName . "<br>";
echo "SCORE = " . $submittedScore . "<br>";
echo "HITS = " . $submittedHits . "<br>";
echo "SHOTS = " . $submittedShots . "<br>";
echo "DATE = " . $submittedDate . "<br>";
$newRecord = new record($submittedName, $submittedScore, $submittedHits, $submittedShots, $submittedDate);
$newRecord->recordEcho();Code: Select all
NAME = scottrick
SCORE = 4949
HITS = 15
SHOTS = 27
DATE = 568798
RECORD=568798 568798 568798 568798 568798Code: Select all
RECORD=scottrick 4949 15 27 568798