Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81912 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64847 invoked from network); 5 Feb 2015 12:25:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2015 12:25:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.180 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.180 mail-vc0-f180.google.com Received: from [209.85.220.180] ([209.85.220.180:48813] helo=mail-vc0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 03/77-27691-F4163D45 for ; Thu, 05 Feb 2015 07:25:52 -0500 Received: by mail-vc0-f180.google.com with SMTP id im6so1318029vcb.11 for ; Thu, 05 Feb 2015 04:25:49 -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:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=pNlLKS6yvnBnbMUStjhRCrIApogvPFKOX/4B658svYQ=; b=PGvIRDamXKXkzTKZp6+qUdbaUeAwzmzO63tnHY+i4LF5qG/GqoZhBV6nYGy2LqI5wU jmmnCYUDM0B4YhEPtt3yqxuj2DhD3F1GLM1JnRDReXeUylaBBCeDSBwnFyNHGDPIevfF YGT2KXiz1CP8fM3nm374N84qNKWNhwUYv36iHmGB8pRUEKHnm2IibaDtwu2iqPhXNuiL fpDkdMiusgb3RG99ykk5FzNiFyowI01sTgrqzXBPWG+cVQcBRH0K0/q+AgfGzdGbCIdY 45RjrhX7Xb18y+/0zRqSti83EJTr0deA33B1ogHexNHnCj43o2RE6PlkFm2F1epddgtk Ki8w== X-Gm-Message-State: ALoCoQmk1HP4jChfEj0ufPRaa2B0TjkvDx7vhCkhhfmbx/jGuRhAU8JQCG04JXdbiOKm0KqcbAOYZwJyFU8B+SDpuHN5ecSyplqlbVUzMFbNha9/8VnqOIp7oXgWibU0u/JbN6nGlsitxOGyhhvUPqg7tDqBpNcmDA== MIME-Version: 1.0 X-Received: by 10.52.103.75 with SMTP id fu11mr1597860vdb.5.1423139149081; Thu, 05 Feb 2015 04:25:49 -0800 (PST) Received: by 10.52.74.73 with HTTP; Thu, 5 Feb 2015 04:25:49 -0800 (PST) In-Reply-To: <7740874.yAST26hVNS@rofl> References: <7740874.yAST26hVNS@rofl> Date: Thu, 5 Feb 2015 16:25:49 +0400 Message-ID: To: Patrick Schaaf Cc: PHP Internals , Yasuo Ohgaki Content-Type: multipart/alternative; boundary=047d7b86d990728165050e56670f Subject: Re: [PHP-DEV] Design by Contract From: dmitry@zend.com (Dmitry Stogov) --047d7b86d990728165050e56670f Content-Type: text/plain; charset=UTF-8 this way we would able to use in constraints any statements. The require/ensure syntax was limited to expressions (to limit users in making side effects). May be we may reuse delare() a bit differently. function foo() { declare(pre=) declare(post=) { } However. I like require/ensure more. Thanks. Dmitry. On Thu, Feb 5, 2015 at 3:13 PM, Patrick Schaaf wrote: > 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 > --047d7b86d990728165050e56670f--