Use PHP to tell a story.
Example: Post 578475
Edit: This post was recovered from search engine cache.
[Challenge] OOProse
Moderator: General Moderators
[Challenge] OOProse
Last edited by McInfo on Thu Jun 17, 2010 3:21 pm, edited 1 time in total.
Re: [Challenge] OOProse
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.
Re: [Challenge] OOProse
Code: Select all
if($you -> can('read',$this)) {
$you -> have('too','much',time('on')) -> your('hands');
}- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
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
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);