Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92900 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91043 invoked from network); 28 Apr 2016 19:43:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Apr 2016 19:43:09 -0000 Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 212.232.25.162 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 212.232.25.162 mx206.easyname.com Received: from [212.232.25.162] ([212.232.25.162:57865] helo=mx206.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0A/1D-28296-BC762275 for ; Thu, 28 Apr 2016 15:43:09 -0400 Received: from cable-81-173-133-226.netcologne.de ([81.173.133.226] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1avrq0-0007tL-9l; Thu, 28 Apr 2016 19:43:00 +0000 Reply-To: internals@lists.php.net References: <571BA0F0.2030400@fleshgrinder.com> <571C82A7.2060706@fleshgrinder.com> <571CB44C.1000704@fleshgrinder.com> <571CBD1E.7020103@fleshgrinder.com> <571DD2A3.2020106@zend.com> <571DEC9E.80407@zend.com> To: Joe Watkins , PHP internals Message-ID: <572267BA.6000701@fleshgrinder.com> Date: Thu, 28 Apr 2016 21:42:50 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="XOh1sEKpPrP0v6urem4vag6Crm98T7U8Q" X-ACL-Warn: X-DNSBL-BARRACUDACENTRAL Subject: Re: Fwd: [PHP-DEV] [RFC] PHP Attributes From: php@fleshgrinder.com (Fleshgrinder) --XOh1sEKpPrP0v6urem4vag6Crm98T7U8Q Content-Type: multipart/mixed; boundary="XqKD75pLiVuexgg8F1SimRLtUQLC4vHNO" From: Fleshgrinder Reply-To: internals@lists.php.net To: Joe Watkins , PHP internals Message-ID: <572267BA.6000701@fleshgrinder.com> Subject: Re: Fwd: [PHP-DEV] [RFC] PHP Attributes References: <571BA0F0.2030400@fleshgrinder.com> <571C82A7.2060706@fleshgrinder.com> <571CB44C.1000704@fleshgrinder.com> <571CBD1E.7020103@fleshgrinder.com> <571DD2A3.2020106@zend.com> <571DEC9E.80407@zend.com> In-Reply-To: --XqKD75pLiVuexgg8F1SimRLtUQLC4vHNO Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Is there a reason why you think that Design by Contract (DbC) should be implemented via annotations/attributes? I personally think that such a system should be implemented directly in the language, like Eiffel has it. I even think that it would be easy to add it without any BC. It might be a bit more complicated to implement thought. [assert] assert.active =3D 1 assert.invariant =3D 1 assert.require =3D 1 ; preconditions assert.ensure =3D 1 ; postconditions class PreconditionError extends AssertionError {} class PostconditionError extends AssertionError {} function hello(string $who): string { return "Hello {$who}\n"; } require { # argument must have content $who !=3D=3D ''; # argument cannot contain unprintable characters ctype_print($who); } hello(''); // PHP Warning: require(): argument must have content: "$who !=3D=3D ''= " // failed in ... hello("\0"); // PHP Warning: require(): argument cannot contain unprintable // characters: "ctype_print($who)" failed in ... class A { private DateTimeImmutable $created; private DateTimeImmutable $changed; function f() {} require {} // Special scope "old" available... ensure { # error message $this->x =3D old::$x - 42; } } ensure { # created cannot be less than changed time $this->created <=3D $this->changed; } --=20 Richard "Fleshgrinder" Fussenegger --XqKD75pLiVuexgg8F1SimRLtUQLC4vHNO-- --XOh1sEKpPrP0v6urem4vag6Crm98T7U8Q Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXIme+AAoJEOKkKcqFPVVrhwIQALb0xeEyExuhMs8Bc2vl9DR6 bTEgaPNdwDxFTrQsN8OT0A6nmgUfpl1dd+JgHygtqoyszDV47nT6p/MtU3HhCJ2t +wXHZo2SLxSVP/bmgmLa+FUt9i5DH77AkiQJ44P6hRmn3iih4mZSxTW2RlmbUKhe Yh0ewkYw2XREXy6c3n48hhXugQw8j+CaoLFdZheVz7eTEQfGkYl8+sscEeOZDWOM vKEAIBHTVvDznLmPPbKMg7ofOv0UhQUqco8m3FhI4DymbOYfygCyHVshiEApGM6J BWcDWGBRb9q4vcXkJ3CVs39xQ1BMc51bD5oIBIy+r22BanLfjtNrM/WGpD3oyS5V aliG1MU4CsSBlq1N9WsUPZV+F3RGVBUQAlS6vLutcw3LQjjxVnyMdK/Y6WOfsAjM Bdq/OXBmCIUl38bHSr36ol63yT1hEEjj00GVMjS2EgFg/J6kyBSHo4e0M4A9djFp qJKlFhH3J5aH5PF7Uk+ldxiV4ECOVLNF6+KhmK4PiXqZQVar+r39SfIYiGRbfJa/ T/yp/LsPIZ+WwolF9MMHXp8K6JUFZ9zu0vaLaaO2uUzXf6Vk4sr/seZEMcPk6nkp +r4EOTrYarQFy1C9uz4IJ7eh3ZTs/FD6xUWxBFRTPneofTqyJlgbwo9niw3JOIfZ yLl1yhskGLV2Bguijaix =JFeQ -----END PGP SIGNATURE----- --XOh1sEKpPrP0v6urem4vag6Crm98T7U8Q--