Skip to content

Instantly share code, notes, and snippets.

@jerclarke
Last active July 25, 2017 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerclarke/686c8c032046e2c29068a7a07e7acf09 to your computer and use it in GitHub Desktop.
Save jerclarke/686c8c032046e2c29068a7a07e7acf09 to your computer and use it in GitHub Desktop.
PHP Love Poem
<?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>";
?>
@jerclarke
Copy link
Author

Originally posted 2011-11-7 on my blog: http://simianuprising.com/2011/11/07/a-love-poem-in-php/
Copied here to track revisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment