vendredi 31 janvier 2020

Comparison Operator is not working in php [duplicate]

what ever i do, i cant get anything else other than NR, it always prints NR, it is not comparing the strings which i pass. please help

class Movie{
    public $name;
    private $rating;

    function __construct($name, $rating){
      $this -> name=$name;
      $this -> setRating($rating);
    }

    function setRating($RATNG){
      if ("G" == $RATING || $RATING == "PG" || $RATING == "PG-13" || $RATING == "R" || $RATING == "NR") {
        $this -> rating = $RATING;
      }else {
        $this -> rating = "NR";
      }
    }
    function getRating(){
      return $this -> rating;
    }
}

$movie1 = new Movie("Avengers", "PG-13");
          //G, PG, PG-13, R, NR
          $movie1 -> setRating("G");
          echo $movie1-> getRating();

Aucun commentaire:

Enregistrer un commentaire