<?php

class DateOfBirth implements \JsonSerializable{
  private $day;
  private $month;
  private $year;

	/*use SetterTrait;
	use GetterTrait;
	use JsonSerializeTrait;*/

  public function __construct($data = null){
    if($data !== null){
      foreach($data as $key => $value){
        $this->$key = $value;
      }
    }
  }

	protected function setDay($day){
		$this->day = $day;
  }

  protected function setMonth($month){
		$this->month = $month;
  }
    
  protected function setYear($year){
		$this->year = $year;
  }

    public function __set($name, $value)
    {
        $setter = 'set'.$name;
        if (method_exists($this, $setter)) {
            $this->$setter($value);
        } else {
            $this->$name = $value;
        }
    }

    public function __get($name){
        return $this->$name;
    }

    public function jsonSerialize()
    {
        $vars = array_filter(get_object_vars($this), function($val){ return $val !== null; });
        return $vars;
    }
}
