Class Including A Complete Collection Of Get And Set Methods.

<?php
class Dog{
    function __construct($name='No-name', $breed='unknown', $price = 15) {
        $this->name = $name;
        $this->breed = $breed;
        $this->price = $price;
    }
    function setName($name) {
        $this->name = $name;
    }
    function setBreed($breed){
        $this->breed = $breed;
    }
    function setPrice($price) {
        $this->price = $price < 0 ? 0 : $price;
    }
    function getName() {
        return $this->name;
    }
    function getBreed() {
        return $this->breed;
    }
    function getPrice(){
        return $this->price;
    }
    function display() {
        printf("<p>%s is a %s and costs \$%.2f.</p>\n", $this->name, $this->breed, $this->price);
    }
}
$magpie = new Dog('Malaysia', 'magpie', 7.5);
$magpie->display();
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.