Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82279 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46372 invoked from network); 9 Feb 2015 13:48:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2015 13:48:52 -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.171 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.171 mail-vc0-f171.google.com Received: from [209.85.220.171] ([209.85.220.171:57165] helo=mail-vc0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 71/C2-50460-1CAB8D45 for ; Mon, 09 Feb 2015 08:48:51 -0500 Received: by mail-vc0-f171.google.com with SMTP id kv19so2917266vcb.2 for ; Mon, 09 Feb 2015 05:48:47 -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=gYJvvV65d3Yd7NQeqSa6a8NJz0zz8HGFkBV/1P9uKxg=; b=CzaSerxVuxegWBLCDTeAPIS36M5lor1SQD5Lkj91CvR3yiEDzHu2N0XBkQYdr4Utz8 q9JJ9HwDdHrD3TiQvOAzGG4V1zzd839XkEx7KVsFZ3jv91c3yfCI7WFR07SGypdpHAvb K+KoVwzwQS5JeZv9mw6K0d4zKx+gGuDIaSSTZZlrYloZRrHHlUQoPv59RhMPJa4kRQV6 ENt4qTiGzZXcBwmceKIKsFYharlZwblFrtFTwfciFD/PaTyfmgwmscEpGR4PpJL9c3HT rQHcQ9LTWR27cHJCCbK++XBdRsqdFxVpUbo4d335nluzuRoLGs1y0fzyyqbC0s4WjDyz AURA== X-Gm-Message-State: ALoCoQnxoWyEI6qVMUc6pIKr2npHSWW0GFiicvmcb68Ybm2NF86/DCU/FrSWJJRIhp0eQLh7XXUPJrbTqYzCtnO3ygE5HuE+YY+iXirkMjEbVt5Vv4RdK3yGJZiU1AG1jq3Z/SN1gieHzaPRWRQdSDCpIp+pyNCisA== MIME-Version: 1.0 X-Received: by 10.221.18.136 with SMTP id qg8mr10052603vcb.27.1423489727323; Mon, 09 Feb 2015 05:48:47 -0800 (PST) Received: by 10.52.74.73 with HTTP; Mon, 9 Feb 2015 05:48:47 -0800 (PST) In-Reply-To: <04ac01d04467$f4259b90$dc70d2b0$@tekwire.net> References: <54D7ED22.3080001@gmail.com> <04ac01d04467$f4259b90$dc70d2b0$@tekwire.net> Date: Mon, 9 Feb 2015 17:48:47 +0400 Message-ID: To: =?UTF-8?Q?Fran=C3=A7ois_Laupretre?= Cc: Joe Watkins , Yasuo Ohgaki , Stanislav Malyshev , Rasmus Lerdorf , PHP Internals Content-Type: multipart/alternative; boundary=001a113399e689f7e8050ea80772 Subject: Re: [PHP-DEV] Design by Contract From: dmitry@zend.com (Dmitry Stogov) --001a113399e689f7e8050ea80772 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Feb 9, 2015 at 3:57 PM, Fran=C3=A7ois Laupretre wrote: > Hi Dmitry, > > > De : Dmitry Stogov [mailto:dmitry@zend.com] > > Envoy=C3=A9 : lundi 9 f=C3=A9vrier 2015 12:05 > > =C3=80 : Joe Watkins > > Cc : Yasuo Ohgaki; Stanislav Malyshev; PHP Internals > > Objet : Re: [PHP-DEV] Design by Contract > > > > invariant is for classes only. It should be called before and/or after > each > > method to check object consistency. > > > > syntax with expressions may work if we put constraints before the > function > > body . > > > > function foo($a int): int > > require(expr1) > > require(expr2, msg) > > return(expr3) > > { > > } > > I understand you're defining an implementation based on assertions only, > despite the fact that 'require' and 'return' are very ambiguous choices I= MO. > > Did you take into account that, in many cases, this would revert to stric= t > type checking, due to the way is_xxx() functions are working ? > > If someone writes 'function tan($op) / require (is_float($op));' will he > expect tan(1) to be rejected ? (we're back to Rasmus' complaint). > You'll get exactly what you write in constraint, no any predefined semantic, no need to learn predefined rules. > > The same with is_int() and others, they're all based on zval types. Only > is_numeric() is smarter and allows specifying a 'number' in the PHP way. > Unfortunately, these functions are wrong as they don't fit with the way > people are used to consider types in PHP. So, no easy way to say you can > accept 1 or 1.0, let alone "1". > > That's why my proposal features assertions AND 'smart' argument types. > Actually, types are more important than assertions because that's what > people will use first. Primary use for assertions will be checking > conditions between args. The same for properties and return type. Actuall= y, > I would say that most phpdoc-annotated code already contains most DbC > constraints it needs. We just need to formalize and use them. > I think, people will use type hinting first (in a way they'll be implemented in PHP-7). Thanks. Dmitry. > As others already said here, be it for type checking or DbC, we need a > mechanism to interpret types the 'PHP' way, something between PHP > permissive type juggling and strict zval-based typing. That's what I trie= d > to define. > > I understand the prevention against inserting PHP code in doc comments > and, if I was designing the language from scratch, I wouldn't use such a > design. But, considering every aspects of the problem, I still think it's > the best compromise to add the feature. > > Regards > > Fran=C3=A7ois > > > --001a113399e689f7e8050ea80772--