rfc:dbc2
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:dbc2 [2015/02/10 12:25] – krakjoe | rfc:dbc2 [2015/02/10 21:44] – typo yohgaki | ||
---|---|---|---|
Line 41: | Line 41: | ||
===== Pre and Post Condition ===== | ===== Pre and Post Condition ===== | ||
- | These contracts should be defined after the function declaration, | + | These contracts should be defined after the function declaration, |
- | Multiple precondition and postcondition contracts may be used. The expressions are just a regular PHP expressions. They have access | + | Multiple precondition and postcondition contracts may be used. The expressions are just a regular PHP expressions. They are evaluated in the function scope, and can access arguments |
< | < | ||
Line 70: | Line 70: | ||
===== Invariant ===== | ===== Invariant ===== | ||
- | Invariant contracts are declared using **require** inside class body. Multiple contracts may be used. They may access object or static properties through **$this** and **self**. Invariant contracts may be used for classes, abstract classes and traits, but not for interfaces. | + | Invariant contracts are declared using **require** inside class body. Multiple |
< | < | ||
Line 102: | Line 102: | ||
</ | </ | ||
- | **Invariants | + | **Invariant contracts |
====Contracts Inheritance Rules==== | ====Contracts Inheritance Rules==== | ||
- | **TODO** | + | |
+ | Contracts are constant, this has the following implications: | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | Thus, given the following code: | ||
+ | |||
+ | < | ||
+ | class Child { | ||
+ | require ($this-> | ||
+ | |||
+ | public function someMethod($input) | ||
+ | require(somethingAbout($input)) { | ||
+ | /* ... */ | ||
+ | } | ||
+ | |||
+ | /* ... */ | ||
+ | } | ||
+ | |||
+ | class Monster extends Child { | ||
+ | require ($this-> | ||
+ | |||
+ | public function someMethod($input) | ||
+ | require(somethingElseAbout($input)) { | ||
+ | /* ... */ | ||
+ | } | ||
+ | |||
+ | /* ... */ | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | //Monster// must not break **any** contract in //Child//. | ||
====Execution Control==== | ====Execution Control==== | ||
Line 115: | Line 147: | ||
* dbc=zero_cost - don't generate code for contracts. This may be set only in php.ini and can't be changed through ini_set(). | * dbc=zero_cost - don't generate code for contracts. This may be set only in php.ini and can't be changed through ini_set(). | ||
- | The default value if " | + | The default value is " |
- | ===Contracts | + | ===Contracts |
If " | If " | ||
- | - all require() contracts (preconditions) defined for this methods | + | - all require() contracts (precondition) defined for this function |
- | - all require() contracts (invariants) defined | + | - all require() contracts (invariant) for this class and parents |
- method body | - method body | ||
- | - all require() contracts (invariants) defined | + | - all require() contracts (invariant) for this class and parents |
- | - all return() contracts (postconditions) defined for this methods | + | - all return() contracts (postcondition) defined for this function |
**Invariant and Special Methods** | **Invariant and Special Methods** | ||
Line 131: | Line 163: | ||
* < | * < | ||
* < | * < | ||
- | |||
- | **Class Inheritance** | ||
- | |||
- | * When parent class methods are called, DbC conditions are executed | ||
- | * Special methods execution exception is the same | ||
**Static Call** | **Static Call** | ||
- | * Only pre/post contracts | + | * Only pre and post conditions |
- | + | ||
- | **Interface** | + | |
- | + | ||
- | * Cannot define DbC contracts. | + | |
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 215: | Line 238: | ||
===== Rejected Features ===== | ===== Rejected Features ===== | ||
Keep this updated with features that were discussed on the mail lists. | Keep this updated with features that were discussed on the mail lists. | ||
- |
rfc/dbc2.txt · Last modified: 2018/03/01 23:19 by carusogabriel