shindakioku / overload
php 中的 overload 包
1.0.0
2017-07-03 10:18 UTC
Requires
- phpunit/phpunit: ^6.2
This package is auto-updated.
Last update: 2024-09-29 04:19:47 UTC
README
这个类做一些魔法操作
该类允许您使用40%的(ad hoc)方法重载。
为什么是40%?因为在 PHP 中不允许声明同名方法。
使用该类
class Bar {} class Foo { public function withoutArguments(): string { return 'string'; } public function argument1(string $name): string { return $name; } public function argument2(int $number): int { return $number; } public function withObject(Bar $bar): Bar { return $bar; } } $overload = new Overload\Overload( new Overload\OverloadClass(Foo::class), 'argument1', 'argument2' ); $overload->call('shinda'); // argument1 $overload->call(2); // argument2 $bar = (new Overload\Overload( new Overload\OverloadClass(Foo::class), 'withObject' ))->call(new Bar); // $bar = Bar object; (new Overload\Overload( new Overload\OverloadClass(Foo::class), 'withoutArguments' ))->call(); // 'string'