PHP interface type hinting

In interfaces you can force the return type

interface InterfaceTest {
    function GetSingleEntity(): Entity;
    function GetEntitySet() : Entity[];
}

GetEntitySet should return a array containing Entities. But this kind of syntax is not allowed.
You could just change it to only return an array, but the forcing of the class is the most powerful.
The best is to create a wrapper class for the entities, best would be to use an Iterator.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.