コード例 #1
0
    public function getGender()
    {
        if ($this->gender) {
            return $this->gender;
        } else {
            throw new Exception("Empty value found for gender");
        }
    }
    public function __construct($name, $brand, $price, $type, $size, $color, $gender)
    {
        parent::__construct($name, $brand, $price);
        $this->size = $size;
        $this->type = $type;
        $this->color = $color;
        $this->gender = $gender;
    }
    public function provideDescriptionForProductType()
    {
        try {
            return "This is an article of clothing. It is a " . $this->getBrand() . " " . $this->getColor() . " " . $this->getGender() . " " . $this->getType() . " of size " . $this->getSize() . " it costs " . $this->getPrice();
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    }
}
$shirt = new Clothing("Button Down Shirt", "J Peterman", '29.88', "shirt", "medium", "red", "male");
echo $shirt->provideDescriptionForProductType();
?>
    </p>
  </body>
</html>