$rosie = new RoseBush;
$rosie->plant();
$rosie->shred_flesh();
$rosie->fertilize();
$rosie->weed();
$rosie->water();
class RoseBush extends Plant {
function shred_flesh() {
return "OW, dammit!";
}
}
class Plant extends EverythingIOwn {
var $planted = FALSE;
function plant() { // the verb, that is.
$this->planted = TRUE;
if (rand(1, 10) > 7) { die(); }
}
function water() {
return '...';
}
function weed() {
return '...';
}
function fertilize() {
return '...';
}
}
abstract class EverythingIOwn {
var $safe_from_puppy = FALSE;
function puppy() {
if (!$this->safe_from_puppy) { die(); }
}
}
$rosie->puppy();
// :(
(I wrote this "code poem" a year and a half ago, when we first moved up to Washington and got the puppy. I was reminded of it today while discussing PHP 5.3 objects, and I decided to migrate it from a Facebook note.)
Technologies: