Adding getter
and setter
methods in PhpStorm is equally easy. All you need to do is have a member variable of the class. In the PizzaDish
example, it was dishName
.
To create getters and setters for dishName
, PhpStorm provides that if you need to. Access the right-click context menu for the target variable, click on Generate and select Getters and Setters from the pop up. PhpStorm will create the desired getters and setters for the selected member.
Your PizzaDish
class will now look like the following piece of code:
<?php require_once 'Dish.php'; class PizzaDish extends Dish{ private $dishName; /** * @param mixed $dishName */ public function setDishName($dishName) { $this->dishName = $dishName; } /** * @return mixed */ public function getDishName() { return $this->dishName; } function add($ingredientName){ $this->setDishName($ingredientName); parent::add($this->dishName); } }