Academically, this is called union of types .
Type union in PHP
You can cheat by creating interfaces, parent types, etc., As mentioned in other answers, but what's the point besides adding complexity and LoC to your project? In addition, this cannot work for scalar types, since you cannot extend / implement a scalar type.
, , . , / , - , .
PHP... , . , , .
, :
function myFunction($multiTypeArgument)
{
IDE . , ..
API ( PHP ..) API.
@tilz0R - :
function log($message) {
if (!is_string($message) && !$message instanceof Message) {
throw new \InvalidArgumentException('$message must be a string or a Message object.');
}
}
PHP ()
14 2015 PHP RFC PHP 7.1. 18 "" 11 "".
RFC , PHP , (User|File
).
RFC , , , , , , , (, " , "", ").