Skip to content

Instantly share code, notes, and snippets.

@aligoren
Forked from francescoagati/extensions.php
Created February 21, 2017 10:56
Show Gist options
  • Save aligoren/750b52b83db375662efa8b5b9c34ea98 to your computer and use it in GitHub Desktop.
Save aligoren/750b52b83db375662efa8b5b9c34ea98 to your computer and use it in GitHub Desktop.
simple extension method with reflection and __call in php
<?php
class St {
public static function pippa($obj) {
print_r($obj);
}
}
class Wrapper {
public static $extension_class='St';
public function __call($name,$arguments) {
$reflectionMethod = new ReflectionMethod( self::$extension_class, $name);
return $reflectionMethod->invokeArgs(null, array_merge(array($this),$arguments));
}
}
$obj=(new Wrapper());
$obj->pippa();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment