Type hint for a file or file-like object?

Use either the typing.TextIO or typing.BinaryIO types, for files opened in text mode or binary mode respectively. From the docs: class typing.IO Wrapper namespace for I/O stream types. This defines the generic type IO[AnyStr] and aliases TextIO and BinaryIO for respectively IO[str] and IO[bytes]. These representing the types of I/O streams such as returned by … Read more

Is it possible to specify multiple return types on PHP 7?

As of PHP 8+, you may use union types: function test(): FailObject|SuccessObject {} Another way, available in all versions since PHP 4, is for the two objects to share an interface. Example: interface ReturnInterface {} class FailObject implements ReturnInterface {} class SuccessObject implements ReturnInterface {} function test(): ReturnInterface {} In this example, ReturnInterface is empty. … Read more