Example #1
0
    {
        print "{$this->name} gently shimmers...<br>\n";
    }
}
// end GC class def
class BitterCritter extends Critter
{
    function __construct()
    {
        $this->name = "none of your business";
    }
    // end BC constructor
    function glower()
    {
        return "Grrrrr...<br>\n";
    }
}
// end BitterCritter class def
$first = new Critter("Orville");
$second = new Critter();
$third = new BitterCritter("George");
$fourth = new GlitterCritter("Gloria");
print $first->sayName();
print $second->sayName();
print $third->sayName();
print $third->glower();
print $fourth->glow();
?>
</body>
</html>
Example #2
0
        $this->name = $handle;
    }
    // end constructor
    function setName($newName)
    {
        $this->name = $newName;
    }
    // end setName
    function getName()
    {
        return $this->name;
    }
}
// end Critter class
//make an instance of the critter
$theCritter = new Critter();
//print original name
print "Initial name: " . $theCritter->getName() . "<br>\n";
print "Changing name...<br>\n";
$theCritter->setName("Melville");
print "New name: " . $theCritter->getName() . "<br>\n";
?>
</body>
</html>