I am learning how to call the function of a class in PHP, and I wrote some example for my practice.
<?php
// Class of car
class Car{
var $type;
var $modelNo;
var $seats;
var $colour;
function getType(){
return $type;
}
function getModelNo(){
return $modelNo;
}
function getSeats(){
return $seats;
}
function getColour(){
return $colour;
}
function __construct($type, $modelNo, $seats, $colour){
$this->type = $type;
$this->modelNo = $modelNo;
$this->seats = $seats;
$this->colour = $colour;
}
}
// Create an object of type Car
$myCar = new Car("sports", "A123", 2, "red");
// Getting information about the car
echo "Car type: " . $myCar->getType();
?>
Although I have called getType() function, nothing has been returned, thus the result:
Question
Gundamdriver
I am learning how to call the function of a class in PHP, and I wrote some example for my practice.
Although I have called getType() function, nothing has been returned, thus the result:
Did I miss something?
Thanks.
Link to comment
Share on other sites
8 answers to this question
Recommended Posts