On 2015-02-05, Dmitry Stogov <dmi...@zend.com> wrote: > --001a11c20e52da1ee0050e556679 > Content-Type: text/plain; charset=UTF-8 > > Hi Yasuo, > > Following our conversation, I tried to imagine how DbC should look like in > PHP from user perspective. Finally, I was influenced by the semantic > proposed in D, and syntax proposed for Java. So, these are my initial > thoughts: > > For php it may look like the following: > > function foo() > requre(<input-assert-expression>) > ensure(<output-assert-expression>) > { > ... > } > > It would require only one new reserved word "ensure". > > The assert expressions may be checked or not depending on ini directive. > It should be also possible to prevent code generation for assertions (zero > cost asserts). It was already implemented for > https://wiki.php.net/rfc/expectations
I really like the idea. D allows complete blocks that then use assert. Might be worht investigating why they went for a block rather than one expression. > For inherited methods, only the self <input-assert-expression> should be > checked, and all parent <output-asser-expression>. This is borrowed from D > but not necessary to be repeated exactly. > > I think we shouldn't introduce "invariant" constraints for classes now. May > be later. I believe invariant is one of the strongest contract ideas as it goes well with proper encapsluation and immutability like structures. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php