Viewing file: 14.php (1.25 KB) -rw-rw-rw- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
class Message {
var $message;
function Message() {}
function setMessage($message)
{
$this->message = $message;
}
function getMessage()
{
return $this->message;
}
}
class PoliteMessage extends Message {
function PoliteMessage()
{
$this->setMessage('How are you today?');
}
}
class TerseMessage extends Message {
function TerseMessage()
{
$this->setMessage('Howzit?');
}
}
class RudeMessage extends Message {
function RudeMessage()
{
$this->setMessage('You look like *%&* today!');
}
}
class MessageReader {
var $messages;
function MessageReader(& $messages)
{
$this->messages = & $messages;
$this->readMessages();
}
function readMessages()
{
foreach ( $this->messages as $message ) {
echo ( $message->getMessage().'<br />' );
}
}
}
$classNames = array ('PoliteMessage','TerseMessage','RudeMessage');
srand ((float)microtime()*1000000);
shuffle ($classNames);
$messages = array();
for ( $i = 0; $i < 10; $i++ ) {
shuffle($classNames);
$messages[] = new $classNames[0]();
}
$messageReader = new MessageReader($messages);
?>
|