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

This package is not auto-updated.

Last update: 2024-12-17 04:26:52 UTC


README

Latest Stable Version Build Status License ![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 {

}