protected $fix = 50; public function __construct($type) { parent::__construct('PC', $type); } public function getScore() { return 0.5 * parent::getScore() + $this->fix; } } class AI extends Subject { protected $fix = 10; public function __construct($type) { parent::__construct('AI', $type); } public function getScore() { return parent::getScore() - $this->fix; } } $ob = new Score(); $ob->addObSuject('student', 'Math'); $ob->addObSuject('student', 'English'); $ob->addObSuject('student', 'PC'); $ob->addObSuject('student', 'AI'); $ob->addObSuject('teacher', 'Math'); $ob->addObSuject('teacher', 'English'); $ob->addObSuject('teacher', 'PC'); print_r($ob->getScores());