Hi Stanislav, Yes, as you are saying, it is no easy task. I believe it would make a nice feature, though. I don't know it is really necessary to use union types, I believe that with a class hierarchy would suffice. But maybe there is something that I'm not looking at right, and the unions are needed. It would certainly need some kind of generics or templates, though I don't know how powerfull they ought to be. In fact, having generics was something that also came into my mind when dealing with this project, since I would use the Builder Patter for my Entities, had a couple of Entities that extended one from the other and I couldn't play it nice with the Type Hinting.
Maybe is as Jakub told me, and PHP is not aiming to be Java nor anything similar in anyway. But I believe that if it is moving into type checking, it means that the community is seeing it as something needed. So it would be interesting maybe to have something similar to TypeScript, something like Gradual Typing. But to have that, everything from both worlds must work. Thanks for the reply. Kind regards, Facundo On Mon, Mar 28, 2016 at 9:13 PM, Stanislav Malyshev <smalys...@gmail.com> wrote: > Hi! > > > maybe PHP can. Maybe PHP will give me the polymorphism at execution time > to > > discern an empty Maybe from the one that is not. So I don't have to check > > In order for that to work, we should have a facility to: > a) define union types > b) ensure somehow that code dealing with the union type covers all variants > c) if we really want to be able to handle such types smoothly, we need > something like monads to be able to convert f(SomeClass $x) to f(Maybe $x). > > This does not sound trivial at all. (c) is not strictly required for the > rest to work, but will also require some kind of generics, since Maybe > should have information about contained type (maybe what? maybe file, > maybe database connection, maybe pastrami sandwich?). If you give up on > (c), you still need some facility like case-of for (b). > > And, of course, you will still need to write code to cover the "nothing" > case of the Maybe. So it might be easier getting a code analyzer that > would just identify missing null checks? > > -- > Stas Malyshev > smalys...@gmail.com >