<?php class Orig1 { public static function test() { echo "ok1\n"; } } class Orig2 { public static function test() { echo "ok2\n"; } } class Delegator { public static function delegate(object $orig) { static $cache = []; $origClass = get_class($orig); if (!isset($cache[$origClass])) { $className = 'Delegate__' . count($cache); $cache[$origClass] = $className; eval(" class $className { public static function __callStatic(\$name, \$args) { return $origClass::\$name(...\$args); } } "); } return new $cache[$origClass]($orig); } } $o1 = new Orig1(); $d1 = Delegator::delegate($o1); $o2 = new Orig2(); $d2 = Delegator::delegate($o2); $d1::test(); $d2::test(); $d1::test();
You have javascript disabled. You will not be able to edit any code.