Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82341 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27106 invoked from network); 10 Feb 2015 07:25:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Feb 2015 07:25:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.51 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.216.51 mail-qa0-f51.google.com Received: from [209.85.216.51] ([209.85.216.51:53302] helo=mail-qa0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 25/A9-47508-652B9D45 for ; Tue, 10 Feb 2015 02:25:10 -0500 Received: by mail-qa0-f51.google.com with SMTP id i13so6562234qae.10 for ; Mon, 09 Feb 2015 23:25:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=CmlBv0aeBuufZmp38fJKlj2s8jxKKQtdfugVRfBJfWU=; b=deCEypC1mmP9qNLN0oE6aN4CG6uKAbJvf3DmdFZTsCwLrVvpG2DNyIQlP6Ap6OniF9 IH2jki6IfYrSCw50M1lDIkkd+n3Wp4Y8NKysISAQKI16P2Hmz1Tsj/DH4wB2LxIUWfZT z8vZ88itLhNQzK5nEpjJDiEnaOQleId9uv+HA/Qn30MSFLcPIcL14cubnfWSD35K2/z9 1va0B/BFbRsU4Jwkr4EehOxct5rESX8c/C1PTXwC3zjNmvBHkPQGzdS4jrF4iIb1O4YV Rx/Q+JMjuR9jx7NyWIUKbS/S00kNTrDUJMHe/TAuheDVir4Kr5iH82ehdGXo636OH4mX 29Uw== X-Received: by 10.224.53.194 with SMTP id n2mr6029591qag.21.1423553108255; Mon, 09 Feb 2015 23:25:08 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.229.35.200 with HTTP; Mon, 9 Feb 2015 23:24:28 -0800 (PST) In-Reply-To: References: <54D7ED22.3080001@gmail.com> Date: Tue, 10 Feb 2015 16:24:28 +0900 X-Google-Sender-Auth: dFQDHB76FlpKSw4EcesDUNSr1SQ Message-ID: To: Patrick Schaaf Cc: internals , Dmitry Stogov Content-Type: multipart/alternative; boundary=001a1132f74456290c050eb6c9c9 Subject: Re: [PHP-DEV] Design by Contract From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a1132f74456290c050eb6c9c9 Content-Type: text/plain; charset=UTF-8 Hi Patrick, On Tue, Feb 10, 2015 at 4:06 PM, Patrick Schaaf wrote: > Am 10.02.2015 07:25 schrieb "Yasuo Ohgaki" : > > > > https://wiki.php.net/rfc/dbc2 > > First of all, thanks for your effort so far. > > Some questions, after reading the RFC, with no particular order: > > 1) Regarding invariants: those will be called for method calls on objects. > What about static class methods? Could we have static class invariants > (static require(.....))? Would these be called for both static and > nonstatic method calls (nonstatic method calls can change static class > state, too) > Static calls should not use $this->var, so invariant condition is ignored. It should be in the RFC. > 2) the pre- and postconditions could be useful for ordinary, non-OO > functions, too, to check parameters, return, and global state invariants > I proposed __invariant() function, but some would not like to have it. Since you've requested, we may consider again. Rre/postconditions (require/return) can be used for non-OO functions. It should be in the RFC. I'll add it in the RFC later. > 3) I think that method preconditions are not sufficient. Pretty often, > public methods first sanitize and validate their input parameters, and > rightly so. In these cases, it would be useful to have the checking, in the > same general framework, at an arbitrary point in the function body. In > other words, assert (with an expression as the first argument, instead of a > string....). > I might misunderstand you. Anyway, assert( $var > 0 ) is allowed. So you can write usual PHP code. Even we can assert( foo() ) // The same applies to require()/return() is allowed. However, PHP does not allow in place closure call currently. We cannot do assert(function() { return $a > 0;} ) It's just ignored. This is the same as current assert(). > 4) regarding the error message second argument to the condition > definitions, it would be useful to have these not only as plain > (extrapolated) strings, but as full expressions-that-evaluate-to-string. > That would permit hooking to arbitrary private logging and log formatting > methods. > assert( $var > 0, '$var must be positive') is allowed. This should be in the RFC. require()/return() works just like assert(). > 5) and a bit off-topic, it would be useful to be able to declare (sic) > whole methods to be nonproduction only: Methods that will only be used in > pre/post/invariant condition expresions (or error formatters a la my point > 4) > Do you mean enable DbC partially? Like declare(dbc=1); At the top of script? I think it would not happen, but others may think it should. Anyone? Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a1132f74456290c050eb6c9c9--