[Challenge] OOProse

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

[Challenge] OOProse

Post by McInfo »

Use PHP to tell a story.

Example: Post 578475

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Thu Jun 17, 2010 3:21 pm, edited 1 time in total.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: [Challenge] OOProse

Post by pickle »

Code: Select all

$I->laughed();
$I->cried();
$I->went('home');
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: [Challenge] OOProse

Post by Eran »

Code: Select all

if($you -> can('read',$this)) {
    $you -> have('too','much',time('on')) -> your('hands');
}
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post 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';
 
 
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: [Challenge] OOProse

Post 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.
Post Reply