mardi 4 avril 2017

Function and if else in PHP

i dont understand how the if statement works and the function is called, why i am getting "He has more strength", i know because the strength is greater, but what i am getting there, is it a boolean? can i dump it, it shows me NULL if i put this inside the if statement

<?php
class Ship
{
public $name;
public $strength = 0;

    public function doesGivenShipHaveMoreStrength($givenShip)
    {
          $givenShip->strength > $this->strength;
    }
}

$myShip = new Ship();
$myShip->name = 'TIE Fighter';
$myShip->strength = 150;

$otherShip = new Ship();
$otherShip->name = 'Imperial Shuttle';
$otherShip->strength = 50;


if ($myShip->doesGivenShipHaveMoreStrength($otherShip)) {

 echo $otherShip->name.' He has more strength';

} else {
    echo $myShip->name.' She has more strength';

}


?>

Aucun commentaire:

Enregistrer un commentaire