Last active
July 25, 2017 02:16
-
-
Save jerclarke/686c8c032046e2c29068a7a07e7acf09 to your computer and use it in GitHub Desktop.
PHP Love Poem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
try_love(); | |
function try_love() { | |
echo "<div class='this-world'>"; | |
$me = new Lover ( 'Me' ); | |
$you = new Lover ( 'You' ); | |
$me->add_companion( $you ); | |
$me->have_feelings( $you, array( | |
'adore', | |
'long for', | |
'desire', | |
'love', | |
)); | |
$me->express_feelings( $you ); | |
if ( $you->have_feelings( $me ) ) : | |
// $you->express_feelings( $me ); | |
// $me->process_feelings( $you ); | |
endif; | |
echo "</div>"; | |
} | |
class Lover { | |
public $name = ''; | |
public $feelings = ''; | |
public function __construct( $name ) { | |
$this->name = $name; | |
} | |
public function add_companion($other) { | |
$this->partners[$other->name] = $other; | |
} | |
public function remove_companion($other) { | |
unset($this->partners[$other->name]); | |
$this->have_feelings(array('loss')); | |
} | |
public function have_feelings($other, $feelings = array()) { | |
foreach ($feelings AS $feeling) | |
$this->feelings[$other->name][] = $feeling; | |
} | |
public function remove_feelings($feelings = array()) { | |
error_log("Love Error: No method to remove feelings"); | |
} | |
public function express_feelings($other) { | |
$feelings_for_other = $this->feelings[$other->name]; | |
foreach ($feelings_for_other AS $feeling_for_other ) | |
echo "I $feeling_for_other {$other->name} <br> "; | |
} | |
public function process_feelings($param) { | |
// TODO | |
} | |
} | |
/** | |
* Stuff it said in the process | |
*/ | |
$dev_outputs = array( | |
"I love you", | |
"I Array you", | |
); | |
echo "</div>"; | |
echo "<style type='text/css'>.this-world {position: fixed; top: 50%;left: 50%; transform: translate(-50%, -50%); font-size:3em;}</style>"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Originally posted 2011-11-7 on my blog: http://simianuprising.com/2011/11/07/a-love-poem-in-php/
Copied here to track revisions.