Skip to content

Instantly share code, notes, and snippets.

@Zegnat
Created February 23, 2011 08:56
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 Zegnat/840189 to your computer and use it in GitHub Desktop.
Save Zegnat/840189 to your computer and use it in GitHub Desktop.
The lol class will let you code your applications with the word lol only! (Or any other word.)
<?php
class lol {
private $functions;
function __construct() {
$functions = get_defined_functions();
$this->functions = $functions['internal'];
}
public function __call($name, $arguments) {
$l = $i = strlen($name);
$repeater = '';
$times = 0;
while ($i--) {
$repeater .= $name[$l-$i-1];
if (preg_match('#^('.preg_quote($repeater).')+$#i',$name)) {
$times = $times<($a=strlen($name)/strlen($repeater))?$a:$times;
}
}
$times--;
$name = $this->functions[$times];
unset($this->functions[$times]);
array_unshift($this->functions,$name);
return call_user_func_array($name,$arguments);
}
}
$lol = new lol;
print $lol->lollollollollol('teststring').'<br>'; // strlen('teststring') == 10
print $lol->lol('teststring').'<br>'; // strlen('teststring') == 10
$theRing = new lol;
print $theRing->MordorMordorMordorMordorMordor('teststring').'<br>'; // strlen('teststring') == 10
print $theRing->Mordor('teststring').'<br>'; // strlen('teststring') == 10
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment