Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81906 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55637 invoked from network); 5 Feb 2015 12:13:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2015 12:13:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@bof.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php@bof.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain bof.de designates 80.242.145.70 as permitted sender) X-PHP-List-Original-Sender: php@bof.de X-Host-Fingerprint: 80.242.145.70 mars.intermailgate.com Received: from [80.242.145.70] ([80.242.145.70:52223] helo=mars.intermailgate.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7F/65-27691-D7E53D45 for ; Thu, 05 Feb 2015 07:13:50 -0500 Received: (qmail 7948 invoked by uid 1009); 5 Feb 2015 13:13:46 +0100 Received: from 192.109.53.146 by mars (envelope-from , uid 89) with qmail-scanner-1.25-st-qms (clamdscan: 0.96.2/20031. spamassassin: 3.3.1. perlscan: 1.25-st-qms. Clear:RC:0(192.109.53.146):SA:0(1.3/8.0):. Processed in 0.296764 secs); 05 Feb 2015 12:13:46 -0000 X-Spam-Status: No, hits=1.3 required=8.0 X-Spam-Level: + X-Antivirus-MYDOMAIN-Mail-From: php@bof.de via mars X-Antivirus-MYDOMAIN: 1.25-st-qms (Clear:RC:0(192.109.53.146):SA:0(1.3/8.0):. Processed in 0.296764 secs Process 7936) Received: from unknown (HELO rofl.localnet) (gmail@bof.de@192.109.53.146) by mars.intermailgate.com with AES256-SHA encrypted SMTP; 5 Feb 2015 13:13:46 +0100 To: internals@lists.php.net Cc: Dmitry Stogov , Yasuo Ohgaki Date: Thu, 05 Feb 2015 13:13:45 +0100 Message-ID: <7740874.yAST26hVNS@rofl> User-Agent: KMail/4.14.4 (Linux/3.18.5-1.gf378da4-desktop; KDE/4.14.4; x86_64; ; ) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Subject: Re: [PHP-DEV] Design by Contract From: php@bof.de (Patrick Schaaf) On Thursday 05 February 2015 15:14:04 Dmitry Stogov wrote: > > function foo() > requre() > ensure() > { > ... > } > > It would require only one new reserved word "ensure". Regarding syntax.... This could be another place where the irrationally- dreaded declare would make sense: function foo() { declare(pre) { if (whatever...) return false; // arbitrary PHP code } declare(post=$resultvar) { if ($resultvar == XXX) return true; return false; } } This way, no new reserved words are needed at all, and the programmer can give a name to the "variable that holds the result" locally to avoid clashes with anything else in the function. I'm a bit undecided whether returning true/false there to give the verdict, would be the best way. Maybe better would be another use for declare, without a block, to declare that the pre/postcondition failed - giving a nice place to put a suitable message, too. And again without introducing any extra keywords: function foo() { declare(post=$resultvar) { if ($resultvar == XXX) declare(fail="My $resultvar looks fishy"); } } best regards Patrick