lightningspirit / magic-interfaces
Provides PHP Interfaces to test some magic methods using instanceof instead of 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-11-05 03:45:53 UTC
README
![Gitter](https://badges.gitter.im/Join Chat.svg)
PHP Interfaces for magic methods
This package provides interfaces that define PHP magic methods.
Using interfaces to test for existing implementations is often recognized as a best practice.
When testing objects for magic methods implementation, those interfaces can be useful.
Motivation
Instead of:
if (method_exists('__invoke', $object)) {
$object();
}
one can now write:
if ($object instanceof Invokable) {
$object();
}
Usage example
Create a class that implements some magic interfaces.
/**
* Implement some magic methods by using interfaces
*/
class Example implements Invokable, Stringifiable {
}