Re: DbC for PHP?
| From: | Sebastian Krebs | Date: | Tue, 28 Jan 2014 08:36:08 +0000 |
| Subject: | Re: DbC for PHP? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-71660@lists.php.net to get a copy of this message | ||
2014-01-28 Yasuo Ohgaki <yohgaki@ohgaki.net>
> 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.
>
Couldn't you achieve the same with assert()?
>
> 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
> yohgaki@ohgaki.net
>
--
github.com/KingCrunch