Getter and Setter?

前端 未结 15 814
南方客
南方客 2020-11-22 16:47

I\'m not a PHP developer, so I\'m wondering if in PHP is more popular to use explicit getter/setters, in a pure OOP style, with private fields (the way I like):



        
15条回答
  •  暖寄归人
    2020-11-22 17:52

    You can use php magic methods __get and __set.

    $property;
        }
      }
    
      public function __set($property, $value) {
        if (property_exists($this, $property)) {
          $this->$property = $value;
        }
    
        return $this;
      }
    }
    ?>
    

提交回复
热议问题