Send a blank email to [email protected] to get a copy of this message
Hi all,
I'm wandering if we could have DbC (Design by Contract) for PHP 6.
http://en.wikipedia.org/wiki/Design_by_contract
There is user land implementation already.
https://gitorious.org/higher-order-php/php-contracts/source/5b0a53b9732f0e4dbe79345212c84c74526def3b:
It could be done with dbc mode INI switch as follows.
When dbc=on, automatically includes
include __dbc_ . __SCRIPT_NAME__;
when a script is loaded. No error if there is not the script.
When function/method is called
__dbc_pre_. __FUNCTION__() is called before calling function().
__dbc_post_.___FUNCTION__() is called after function() call.
No error if there is not the function.
Class methods would be more complex, but basic idea is the same.
Issue would be what we should do with $this with class methods.
Automatic namespace might be nice to have for both function and class.
When dbc=off, these would be skipped at all.
It does not sacrifice performance at all for production while it could catch
various errors during development. It could do more complex assertion
than assert() and it could check post condition that is difficult to achieve
by assert(). User could have their own strong type safety as long as they
have strict input validation. It could be used as complement of annotation.
Just an idea.
Any comments?
Regards,
--
Yasuo Ohgaki
[email protected]