Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81898 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40994 invoked from network); 5 Feb 2015 11:14:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2015 11:14:09 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.182 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.182 mail-vc0-f182.google.com Received: from [209.85.220.182] ([209.85.220.182:39146] helo=mail-vc0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FA/82-27691-F7053D45 for ; Thu, 05 Feb 2015 06:14:07 -0500 Received: by mail-vc0-f182.google.com with SMTP id kv19so2443468vcb.13 for ; Thu, 05 Feb 2015 03:14:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=/Sx05liV4WcpM29V+fixfHFUxEVcSiIf839k1XAdt8A=; b=VnbthQIh3NCnvMeMc8gKKLSsys5LNgquOrUmvPSWaiWnTzqwildnyrQOZwJNwif1pC 1gG5yzAJddWkz1JqfXiFcqRb5zCtM/1B9iN4jJ8LznKPDJ2b8ZfLfICX/1zKuE9yWD7w UelEYoYedkj/FpJfDpnkQn9UIOXncXzG77WZTqRJuazw3wOkaAqLqbR00Zrf6GY2arSq czLuFYMexg6EKJmnJyZlQpG5eEvm6t5lihvv3gyuuP4MSgNe2OulHseCXxcxJsdS3v+u DyyxDI8tBiRzx5OTFeF78qc3LtD/LzdAyyEDxMZ2jf0M+Xxe3WR0eYhD1Gfyo+XI+HQ3 Yyig== X-Gm-Message-State: ALoCoQnqqRlJ4xoO6iWUf+WIAtBnUKLFHD3jViWlhwD2sN4IGNhafJvMEQ28spRMJpPy7Hr06YFJCRiQfZy1IaABrhcFs9vA/+TyuNmeuCXZPfWAyRfzq1oOCWYK/pub9LpWGpPbyQWB/qGeT7IifRfajlnZFwjo0w== MIME-Version: 1.0 X-Received: by 10.220.98.136 with SMTP id q8mr439459vcn.4.1423134844126; Thu, 05 Feb 2015 03:14:04 -0800 (PST) Received: by 10.52.74.73 with HTTP; Thu, 5 Feb 2015 03:14:04 -0800 (PST) Date: Thu, 5 Feb 2015 15:14:04 +0400 Message-ID: To: Yasuo Ohgaki , PHP Internals Content-Type: multipart/alternative; boundary=001a11c20e52da1ee0050e556679 Subject: Design by Contract From: dmitry@zend.com (Dmitry Stogov) --001a11c20e52da1ee0050e556679 Content-Type: text/plain; charset=UTF-8 Hi Yasuo, Following our conversation, I tried to imagine how DbC should look like in PHP from user perspective. Finally, I was influenced by the semantic proposed in D, and syntax proposed for Java. So, these are my initial thoughts: For php it may look like the following: function foo() requre() ensure() { ... } It would require only one new reserved word "ensure". The assert expressions may be checked or not depending on ini directive. It should be also possible to prevent code generation for assertions (zero cost asserts). It was already implemented for https://wiki.php.net/rfc/expectations For inherited methods, only the self should be checked, and all parent . This is borrowed from D but not necessary to be repeated exactly. I think we shouldn't introduce "invariant" constraints for classes now. May be later. Implementation is going to generate code for input constraint after all RECV opcodes and before code for function body, and code for output constraint before RETURN opcode (may be reusing implementation of "finally"). See: http://dlang.org/contracts.html http://jan.newmarch.name/java/contracts/paper-long.html Thanks. Dmitry. --001a11c20e52da1ee0050e556679--