Advertisement
lucax0x

why 'Art' Index not added in subjects Array

Oct 18th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1. <?php
  2.  
  3. class Student {
  4.    
  5.     private $name;
  6.     private $age;
  7.     private $score;
  8.     private $subjects = array (
  9.         'Arabic'    => 0 ,
  10.         'English'   => 0 ,
  11.         'Math'      => 0 ,
  12.         'Science'   => 0
  13.     );
  14.     private $minScore = 150;
  15.     private $maxScore = 300;
  16.    
  17.     public function __construct($name , $age)
  18.     {
  19.         $this->setName($name);
  20.         $this->setAge($age);
  21.     }
  22.    
  23.     private function setName($name)
  24.     {
  25.         $name = strtolower($name);
  26.         $name = filter_var($name,FILTER_SANITIZE_STRING);
  27.         $name = ucwords($name);
  28.         $name = substr($name, 0 , 30);
  29.         $this->name = $name;
  30.     }
  31.    
  32.     public function getName() {
  33.         return $this->name;
  34.     }
  35.    
  36.     private function setAge($age)
  37.     {  
  38.         $age = filter_var($age, FILTER_SANITIZE_NUMBER_INT);
  39.         $age = abs($age);
  40.        
  41.         if ($age <= 6 || $age  >= 18) {
  42.             throw new Exception("Error");
  43.         } else {
  44.             $this->age = $age;
  45.         }
  46.        
  47.     }
  48.    
  49.     public function getAge() {
  50.         return $this->age;
  51.     }
  52.    
  53.     public function getSubject() {
  54.         return $this->subjects;
  55.     }
  56.    
  57.     public function getMinScore() {
  58.         return $this->minScore;
  59.     }
  60.    
  61.      public function getMaxScore() {
  62.         return $this->maxScore;
  63.     }
  64.    
  65. }
  66.  
  67. class Grade1Student extends Student
  68. {
  69.    
  70.    
  71.    
  72.     public function __construct($name,$age)
  73.     {
  74.         parent::__construct($name,$age);
  75.         $this->minScore=180;
  76.         $this->maxScore=400;
  77.         $this->subjects['Art'] = 0;
  78.     }
  79. }
  80.  
  81. $mohamed = new Grade1Student('Mohamed' , 12);
  82. print_r($mohamed->getSubject());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement