lightningspirit / magic-interfaces
Provides PHP Interfaces to test some magic methods using instanceof instead of method_exists
Installs: 28
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 1
pkg:composer/lightningspirit/magic-interfaces
Requires
- php: >=5.3.1
Requires (Dev)
- phpunit/phpunit: ~4.4
This package is not auto-updated.
Last update: 2025-10-21 08:53:42 UTC
README

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 {
}