# RFC: Introduce Design by Contract

- Status: Inactive
- Authors: Yasuo Ohgaki yohgaki@ohgaki.net
- Date: 2015-02-28
- Version: 1.0
- Original: https://wiki.php.net/rfc/introduce_design_by_contract
- Page: https://externals.io/rfc/introduce_design_by_contract
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

## Votes

### Introduce DbC (closed)

Yes: 0 · No: 0

### DbC implementation (closed)

Annotation: 0 · Definition: 0

## Discussions on the mailing list

- [\[RFC\] Design by Contract - Vote only RFC](https://externals.io/message/84090.md) — started on 2015-03-01, 4 messages

---

## Introduction

Design by Contract(DbC) or Contract Programming is new way of program development that many languages support.

- [http://en.wikipedia.org/wiki/Design\_by\_contract](http://en.wikipedia.org/wiki/Design_by_contract)
- <http://dlang.org/contracts.html>
- <https://archive.eiffel.com/doc/manuals/technology/contract/>
- [Google search result of "Design by Contract"](https://www.google.co.jp/search?q=design+by+contract&qscrl=1)

### Brief DbC description

DbC an approach for designing software. It prescribes that software designers should define formal, precise and verifiable interface specifications for software components, which extend the ordinary definition of abstract data types with preconditions, postconditions and invariants. These specifications are referred to as “contracts”, in accordance with a conceptual metaphor with the conditions and obligations of business contracts. (Wikipedia)

### DbC proposals

There are 2 proposals for DbC.

- [DbC by annotation](https://externals.io/rfc/dbc)
- [DbC by definition](https://externals.io/rfc/dbc2)

Note: DbC by annotation is not whether we'll have “annotation” or not. Annotation may be implemented without DbC.

This RFC is solely for making decision whether PHP will have DbC or not, if PHP will have DbC, which implementation should be used.

## Proposal

Since there are 2 proposals for the same purpose, vote result may not reflect the objective (Have DbC or not) is accepted or not. This RFC only address if PHP is going to have DbC support or not and vote for 2 competing RFCs.

- Vote for DbC introduction - Yes/NO
- Vote for DbC implementation - [Annotation](https://externals.io/rfc/dbc)/[Definition](https://externals.io/rfc/dbc2)

This RFC does not address implementation details at all. Please refer to proposed RFCs for details.

## Proposed PHP Version(s)

PHP 7

## Proposed Voting Choices

Requires a 2/3

**Vote: Introduce DbC** — Yes: 0 · No: 0 (closed)

If you voted “yes” for DbC, please choose implementation. Requires 50%+1. In case we have the same votes, vote period is extended few days.

**Vote: DbC implementation** — Annotation: 0 · Definition: 0 (closed)

Vote starts 2015/3/xx ends 2015/3/xx.

## Implementation

After the project is implemented, this section should contain

1. the version(s) it was merged to
2. a link to the git commit(s)
3. a link to the PHP manual entry for the feature

## References

- [DbC by annotation](https://externals.io/rfc/dbc)
- [DbC by definition](https://externals.io/rfc/dbc2)

Simple assertion/expectation can be used for DbC. However, it lacks “invariant” and “postcondition” support.

- <https://externals.io/rfc/expectations> (Passed. This will be available in PHP7)

## Rejected Features

Keep this updated with features that were discussed on the mail lists.
