On 3/12/2017 11:33 AM, Yasuo Ohgaki wrote: > DbC allows this kind of validation at development time. > I suppose you would like to check requirement at runtime always. > It would be nice to have feature, but I think > > something like __requrie() > > is better name for the method. > IMO, C# like getter/setter is better though. > > http://stackoverflow.com/questions/11159438/looking-for-a-short-simple-example-of-getters-setters-in-c-sharp >
Hey Yasuo! :) Design by Contract is a nice thing, and you know that I would love to see it as part of the language. However, it is not really the solution to the problem that is being described here, since it is a valid state for an order to be empty. The stated Square-Rectangle example is a different beast, and there are many solutions to it. I probably would argue that Rectangle needs to extend Square and not the other way. Square has an extended functionality compared to Rectangle while being fully compatible. DbC would still be nice and would allow us to add real invariant, pre-, and post-conditions. I, as you might remember, would not go for a magic method but rather an extended block, like we see it for if-else or try-catch: class C {} invariant {} // one assert per line function f() {} requires {} // pre-conditions ensures {} // post-conditions -- Richard "Fleshgrinder" Fussenegger -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php