Skip to content
This repository was archived by the owner on Dec 16, 2019. It is now read-only.

Interface for easy identification of classes that implement the magic __toString method.

License

Notifications You must be signed in to change notification settings

Fleshgrinder/php-stringable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Packagist Packagist License

Stringable

Interface for easy identification of classes that implement PHP’s magic __toString method.

Provided is the interface itself that establishes the contract that implementing classes have to have the magic method. As well as a dummy class that can be used in tests as a substitute for doubles, stubs, or mocks.

Installation

Open a terminal, enter your project directory and execute the following command to add this package to your dependencies:

$ composer require fleshgrinder/stringable

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Usage

IMPORTANT
You cannot throw any exceptions in a __toSring method due to Zend engine limitations. Please vote and comment on the this PHP request and lets hope this will be fixed.

Simply implement the interface and PHP’s magic __toString method.

class YourClass implements Stringable {

    /**
     * @inheritDoc
     */
    public function __toString() {
        return '';
    }

}

License

MIT License

About

Interface for easy identification of classes that implement the magic __toString method.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages