The code outputs "I will be going to Los Angeles. The journey will be a distance of 300 miles. We will need to make 2 stop." when it should pull the plural or singular of the word "stop" depending on the number defined in my IF statement (in that case, it should be the plural). I'm guessing that the IF doesn't work as I expected it to because of the way I have constructed the class. Any help fixing it would be appreciated.
class trip {
public $destination;
public $distance;
public $unit;
public $stops = null;
public $transport = null;
function __construct($destination, $distance, $unit, $stops, $transport) {
$this->destination = $destination;
$this->distance = $distance;
$this->unit = $unit;
$this->stops = $stops;
$this->transport = $transport;
}
function getTrip() {
$a = "I will be going to " . $this->destination . ". ";
$a .= "The journey will be a distance of " . $this->distance . " " . $this->unit . ". ";
$a .= "We will need to make " . $this->stops;
if ($this->stops = 1) {
$a .= " stop.";
} else {
$a .= " stops.";
}
$a .= "\n";
echo $a;
}
}
$first = new trip('Los Angeles',300,'miles',2,'airplane');
$first->getTrip();