class member variables in php are also called properties. they represent the state of class instance. yii introduces a class called yii\base\object. it supports defining properties via getter or setter class methods.
a getter method starts with the word get. a setter method starts with set. you can use properties defined by getters and setters like class member variables.
when a property is being read, the getter method will be called. when a property is being assigned, the setter method will be called. a property defined by a getter is read only if a setter is not defined.
step 1 − create a file called taxi.php inside the components folder.
<?php
   namespace app\components;
   use yii\base\object;
   class taxi extends object {
      private $_phone;
      public function getphone() {
         return $this->_phone;
      }
      public function setphone($value) {
         $this->_phone = trim($value);
      }
   }
?>
in the code above, we define the taxi class derived from the object class. we set a getter – getphone() and a setter – setphone().
step 2 − now, add an actionproperties method to the sitecontroller.
public function actionproperties() {
   $object = new taxi();
   // equivalent to $phone = $object->getphone();
   $phone = $object->phone;
   var_dump($phone);
   // equivalent to $object->setlabel('abc');
   $object->phone = '79005448877';
   var_dump($object);
}
in the above function we created a taxi object, tried to access the phone property via the getter, and set the phone property via the setter.
step 3 − in your web browser, type http://localhost:8080/index.php?r=site/properties, in the address bar, you should see the following output.