lightningspirit / magic-interfaces
提供 PHP 接口,通过 instanceof 而不是 method_exists 测试一些魔术方法
1.1.0
2014-12-15 23:42 UTC
Requires
- php: >=5.3.1
Requires (Dev)
- phpunit/phpunit: ~4.4
This package is not auto-updated.
Last update: 2024-09-24 03:13:14 UTC
README

PHP 魔术方法的接口
此包提供接口,用于定义 PHP 魔术方法。
使用接口测试现有实现通常被认为是最佳实践。
在测试对象是否有 魔术方法 实现时,这些接口可能很有用。
动机
而不是
if (method_exists('__invoke', $object)) {
$object();
}
现在可以写
if ($object instanceof Invokable) {
$object();
}
使用示例
创建一个实现一些魔术接口的类。
/**
* Implement some magic methods by using interfaces
*/
class Example implements Invokable, Stringifiable {
}