RE: [PHP-DEV] Design by Contract
| From: | François Laupretre | Date: | Fri, 06 Feb 2015 09:46:35 +0000 |
| Subject: | RE: [PHP-DEV] Design by Contract | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-82032@lists.php.net to get a copy of this message | ||
> De : Ivan Enderlin @ Hoa [mailto:ivan.enderlin@hoa-project.net]
> > Exactly, phpdoc is used as annotation (or comments with some similar
> > syntax) but is definitively not aimed to be annotations.
> Exact. Annotations !== comments. Because PHP has no annotation system,
> we used to use comments for this purpose, but it's a workaround.
It seems this discussion about DbC cannot remain on the DbC subject itself. Some claim we
shouldn't add DbC because it would require a 'new language' (I don't see
where...). Now, the discussion is about annotations, which are another subject as we don't need
this to implement DbC. Well, annotations would be nice, but I won't wait for annotations to
propose DbC !
What we need is to make an extension able to get control from the engine in 3 locations :
- when a script file is read, before any parsing takes place. The file won't be modified but
the extension will use that to read and internalize the constraints associated with the different
script elements.
- When a method or function is called, after arguments are received, and before the function body is
executed. There, we will execute the pre-conditions.
- Just after function return, but still in the function scope. There we will execute
post-conditions.
Class conditions (invariants) are added to pre/post-conditions when appropriate.
Maybe this is already possible from a Zend extension, I don't know. But, even some of these
hooks don't exist yet, they shouldn't be that hard to implement.
François