Re: Re: Improving PHP's type system

From: Date: Wed, 20 Apr 2016 09:46:46 +0000
Subject: Re: Re: Improving PHP's type system
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  Groups: php.internals 
Request: Send a blank email to internals+get-92530@lists.php.net to get a copy of this message
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: [application/pgp-signature] This is a digitally signed message part signature.asc
« previous php.internals (#92530) next »