On Wed, 2016-04-20 at 17:57 +1000, Jesse Schalken wrote:
> 
> With unions:
> 
> function foo(Bar|string $b) {
> 
>     if (is_string($b)) {
>         // ...
>     } else {
>         // I know $b is a Bar here. I don't need to check. :)
>     }
> }

I' still missing a real-life use case for this. There's no operation I
can come up with which works with an object or string.

Unions between object types should be handled via interface.

The only relevant union types I found till now are

  array | Traversable
  array | Countable

and eventually

  array | Offset[Get|Set]

The last one is a bit critical due to the fact that arrays are value
types, whereas objects are reference types so

   function ($a) {
       $a[] = 42;
   }

behaves notably differently between objects and arrays. So that case
might need some thinking. For the others instead of a generic union type
I'd prefer a special array-solution.

johannes

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to