Skip to content

Instantly share code, notes, and snippets.

@phuedx
Last active December 14, 2015 13:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phuedx/5094530 to your computer and use it in GitHub Desktop.
Save phuedx/5094530 to your computer and use it in GitHub Desktop.
Hey, I've just called you, And this is crazy, But I misspelled you, So proxy, maybe?
<?php
class CallMeMaybe
{
public function __call($name, $arguments)
{
$class = new ReflectionClass($this);
$weightedMethods = array();
foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
$methodName = $method->getName();
$weight = levenshtein($name, $methodName);
$weightedMethods[$methodName] = $weight;
}
asort($weightedMethods);
$methods = array_keys($weightedMethods);
$method = $methods[0];
return call_user_func_array(array($this, $method), $arguments);
}
public function helloWorld()
{
return __FUNCTION__;
}
}
$callMeMaybe = new CallMeMaybe();
var_dump($callMeMaybe->helloWrld());
@phuedx
Copy link
Author

phuedx commented Mar 6, 2013

Much cleaner! It's still pretty dirty though...

@jammus
Copy link

jammus commented Mar 6, 2013

You are a bad person.

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