Page 1 of 1

[Challenge] OOProse

Posted: Thu Nov 19, 2009 1:21 pm
by McInfo
Use PHP to tell a story.

Example: Post 578475

Edit: This post was recovered from search engine cache.

Re: [Challenge] OOProse

Posted: Thu Nov 19, 2009 2:28 pm
by pickle

Code: Select all

$I->laughed();
$I->cried();
$I->went('home');

Re: [Challenge] OOProse

Posted: Thu Nov 19, 2009 3:09 pm
by Eran

Code: Select all

if($you -> can('read',$this)) {
    $you -> have('too','much',time('on')) -> your('hands');
}

Posted: Thu Nov 19, 2009 4:09 pm
by Jonah Bron

Code: Select all

echo 'Goldylocks and the Three Bears
 
Goldy sneaked into the three bears house, and stole their HDTV.  Then, the three bears came back.  When they saw her robbing them, they threatened to call the police if she didn\'t give back the TV.  So Goldy got a lawyer, and sued the bears for alleged "aggressive behavior".
 
The End';
 
 

Re: [Challenge] OOProse

Posted: Fri Nov 20, 2009 12:19 pm
by McInfo

Code: Select all

<?php
class Person {
    private $hopes = array();
    public function getHope ($index) {
        return $this->hopes[$index];
    }
    public function appendHope (Hope $hope) {
        return (array_push($this->hopes, $hope) - 1);
    }
}
 
class Hope {
    private $isFulfilled = false;
    private $testFunction;
    private $testArguments;
    public function __construct ($callback, $arguments) {
        $this->testFunction = $callback;
        $this->testArguments = $arguments;
    }
    public function __get ($name) {
        if ($name == 'isFulfilled') {
            return $this->isFulfilled;
        }
    }
    public function testFulfillment () {
        $this->isFulfilled = (true === call_user_func_array($this->testFunction, $this->testArguments));
        return $this->isFulfilled;
    }
}
 
class PHPCode {
    public $isComplete;
    public $isErrorFree;
    public $isObjectOriented;
    public function __construct ($isComplete, $isErrorFree, $isObjectOriented) {
        $this->isComplete = $isComplete;
        $this->isErrorFree = $isErrorFree;
        $this->isObjectOriented = $isObjectOriented;
    }
}
 
$i = new Person();
$i->hopesFulfilled = 0;
$responses = array
(   new PHPCode(false, false, true)
,   new PHPCode(false, false, true)
,   new PHPCode(true, true, false)
,   new PHPCode(true, true, true)
);
$hopeTest = function (PHPCode $code) {
    return ($code->isComplete && $code->isErrorFree && $code->isObjectOriented);
};
foreach ($responses as $response) {
    $hopeIndex = $i->appendHope(new Hope($hopeTest, array($response)));
    $hope = $i->getHope($hopeIndex);
    $hope->testFulfillment();
    if ($hope->isFulfilled) {
        $i->hopesFulfilled++;
    }
}
var_dump($i->hopesFulfilled);
Edit: This post was recovered from search engine cache.