//add one method function glow() { print $this->name . " gently shimmers...<br> \n"; } // end glow //over-ride the setName method function setName($newName) { $this->name = "Glittery " . $newName; } } // end GC class def //make an instance of the new critter $theCritter = new GlitterCritter("Gloria"); //GC has no constructor, so it 'borrows' from its parent print "Critter name: " . $theCritter->getName() . "<br>\n"; //invoke new glow method $theCritter->glow(); ?> </body> </html>
{ 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>