Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71660 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67161 invoked from network); 28 Jan 2014 08:36:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jan 2014 08:36:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=krebs.seb@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.54 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@gmail.com X-Host-Fingerprint: 209.85.216.54 mail-qa0-f54.google.com Received: from [209.85.216.54] ([209.85.216.54:51097] helo=mail-qa0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 15/E9-01140-32C67E25 for ; Tue, 28 Jan 2014 03:36:52 -0500 Received: by mail-qa0-f54.google.com with SMTP id i13so76838qae.27 for ; Tue, 28 Jan 2014 00:36:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=uIkXPLhxbf3X6WqEPJ8Uh0Ay/svAUbEDMJImt52J2uk=; b=ClFqHwB6HkHBeIJ1V24YSzjIaQTA9ZnXTWkgnJ44qk8a+n5JAKLrHTXICIY48cQqwc TuBGgRmxkFkxMO105VEgRhHGtACfyHL/bTaG1oU0M+rUbyC3VntQrWKyzT5WM6zIgWAa Y3VjDHH1UAt0bAywIOL34G7AlrJCGBdGsEPEaqxiVD3oxvhHtJSvY6SWI0eEv8hCBLSX nJFzSbXvonVBe2CQITthGj0ThEYBGRwALVxYwmhy+A0hTDB1u/z76m/Z5D5u6c1+gxd+ d+l9tNNrAW6DGUjKqVgMrlJ8hkTDe9r/UPV/4y8oTp9tQk+Cm3Q/q7VELmC47EZXFq/x Cfwg== X-Received: by 10.229.179.5 with SMTP id bo5mr342735qcb.21.1390898209047; Tue, 28 Jan 2014 00:36:49 -0800 (PST) MIME-Version: 1.0 Received: by 10.140.87.151 with HTTP; Tue, 28 Jan 2014 00:36:08 -0800 (PST) In-Reply-To: References: Date: Tue, 28 Jan 2014 09:36:08 +0100 Message-ID: To: Yasuo Ohgaki Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c2bccaab4a2d04f103b964 Subject: Re: [PHP-DEV] DbC for PHP? From: krebs.seb@gmail.com (Sebastian Krebs) --001a11c2bccaab4a2d04f103b964 Content-Type: text/plain; charset=ISO-8859-1 2014-01-28 Yasuo Ohgaki > Hi all, > > I'm wandering if we could have DbC (Design by Contract) for PHP 6. > http://en.wikipedia.org/wiki/Design_by_contract > > There is user land implementation already. > > https://gitorious.org/higher-order-php/php-contracts/source/5b0a53b9732f0e4dbe79345212c84c74526def3b > : > > It could be done with dbc mode INI switch as follows. > > When dbc=on, automatically includes > > include __dbc_ . __SCRIPT_NAME__; > > when a script is loaded. No error if there is not the script. > When function/method is called > > __dbc_pre_. __FUNCTION__() is called before calling function(). > __dbc_post_.___FUNCTION__() is called after function() call. > > No error if there is not the function. > Couldn't you achieve the same with assert()? > > Class methods would be more complex, but basic idea is the same. > Issue would be what we should do with $this with class methods. > > Automatic namespace might be nice to have for both function and class. > > When dbc=off, these would be skipped at all. > > It does not sacrifice performance at all for production while it could > catch > various errors during development. It could do more complex assertion > than assert() and it could check post condition that is difficult to > achieve > by assert(). User could have their own strong type safety as long as they > have strict input validation. It could be used as complement of annotation. > > Just an idea. > Any comments? > > Regards, > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net > -- github.com/KingCrunch --001a11c2bccaab4a2d04f103b964--