Define getter and setter : Getter Setter « Class « PHP






Define getter and setter


<?php

   class Staff {
      private $name;

      // Getter
      public function getName() {
         return $this->name;
      }

      // Setter
      public function setName($name) {
         $this->name = $name;
      }
   }
?>
           
       








Related examples in the same category

1.Call getter to get value for property
2.Define and call getter method