<?php include '../util.inc'; include 'acct.inc'; start("Account Driver II"); // The idea of adding a name is swiped from the PHP documentation. // Use the extends keyword for inheritence. class NamedAccount extends Account { // The owner of the account. private $owner; // Construct function __construct($owner, $accnts) { parent::__construct($accnts); $this->owner = $owner; } // Set the owner of the account. function set_owner($o) { $this->owner = $o; } // Print the name, too. function pr($targs = "", $karg = 'style="text-align: right; padding-left: 10pt;"', $darg = 'style="text-align: left;"') { echo "Account for ", $this->owner, ":<br>"; parent::pr($targs, $karg, $darg); } } // Not too different. $aca = new NamedAccount('John Smith', array('Jellybeans' => 200, 'Dustbunnies' => 250)); $acb = new NamedAccount ('Alice Jones', array('Snakes' => 500, 'Iguanas' => 220, 'Lizards' => 110)); $aca->pr(); $acb->pr(); echo "<p>"; $aca->xfer('Dustbunnies', 'Jellybeans', 55); $acb->xfer('Iguanas', 'Lizards', 50); $acb->xfer('Snakes', 'Lizards', 80); $aca->pr(); $acb->pr(); ?> </body> </html>