Skip to content

Instantly share code, notes, and snippets.

@tomjn
Created October 11, 2012 11:19
Show Gist options
  • Save tomjn/3871705 to your computer and use it in GitHub Desktop.
Save tomjn/3871705 to your computer and use it in GitHub Desktop.
PHP Levenshtein distance methods
class Example {
public function length(){
return 5;
}
public function __call($name,$arguments){
$methods = get_class_methods($this);
$ldist = 9999;
$currmethod = $name;
foreach($methods as $m){
$distance = levenshtein($name,$m);
if($distance < $ldist){
$currmethod = $m;
$ldist = $distance;
}
}
return call_user_func(array($this,$currmethod),$arguments);
}
}
$example = new Example();
echo $example->elngth();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment