Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82706 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75726 invoked from network); 14 Feb 2015 23:15:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Feb 2015 23:15:09 -0000 Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: php@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:39342] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/71-00421-9F6DFD45 for ; Sat, 14 Feb 2015 18:15:08 -0500 Received: (qmail 9418 invoked from network); 15 Feb 2015 00:14:27 +0100 Received: from cm56-153-252.liwest.at (HELO RoLaptop) (86.56.153.252) by ns73.kreativmedia.ch with ESMTPSA (AES256-SHA encrypted, authenticated); 15 Feb 2015 00:14:27 +0100 To: "'Yasuo Ohgaki'" Cc: "'francois'" , "'Dmitry Stogov'" , "'Joe Watkins'" , "'Stanislav Malyshev'" , "'PHP Internals'" References: <54DAFD32.3000005@gmail.com> <54DB0BC0.20304@gmail.com> <54DBA801.8060403@gmail.com> <011e01d04802$cbd7 8ce0$6386a6a0$@php.net> <013801d0481d$d34c5170$79e4f450$@php.net> <002701d04846$50c0d630$f2428290$@tutteli.ch> In-Reply-To: Date: Sun, 15 Feb 2015 00:14:24 +0100 Message-ID: <006f01d048ab$f98ded60$eca9c820$@tutteli.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQGgxP9HPTh52uHWkGo6jLSeXRdtNAHjmxmHAVkKc8gBfNJbegGHSzWZAVLQRzQCoXlWsAGB4HqFAsDJgekCOAevPAH9iUyEAXhQrm4CanwAQAHshXVfAlKjS7cCbhkxVQIKeBV9APjJnAEBrgPzSAIhkFZaAaJwrNcA1QgPLZwbjQIQ Content-Language: de-ch Subject: AW: [PHP-DEV] Design by Contract From: php@tutteli.ch ("Robert Stoll") Hi Yasuo > -----Urspr=C3=BCngliche Nachricht----- > Von: yohgaki@gmail.com [mailto:yohgaki@gmail.com] Im Auftrag von Yasuo = Ohgaki > Gesendet: Samstag, 14. Februar 2015 23:54 > An: Robert Stoll > Cc: francois; Dmitry Stogov; Joe Watkins; Stanislav Malyshev; PHP = Internals > Betreff: Re: [PHP-DEV] Design by Contract >=20 > Hi Robert, >=20 > D and PHP differs a lot with respect to types. D is very strongly = typed while PHP is very weakly typed. > Therefore, we need a little different approach. >=20 > On Sat, Feb 14, 2015 at 8:06 PM, Robert Stoll wrote: >=20 > > The theory is actually quite simple. Roughly it says that if you use = a > > type hint of a certain class then you can rely on all > > pre/post-conditions of this class even if a sub-class is passed. = Hence > > the sub-class cannot have more restrict conditions. Consider the > > following (no longer sure which syntax is the one you intend to use, = so I just use pre and post): > > > > class A{ > > function foo($x){ > > pre($x > 100); > > } > > } > > > > class B extends A{ > > function foo($x){ > > pre($x > 50); // less restrictive, that's fine > > } > > } > > > > class C{ > > function foo($x){ > > pre($x > 150); //more restrictive that's not allowed > > } > > } > > > > function foo(A $a){ > > $a->foo(101); // that is ok as long as LSP is not violated } > > > > foo(new A()); //that's fine > > foo(new B()); //fine as well > > foo(new C()); //nope, C violates LSP and thus will result in an = error > > >=20 > Correct. D does not allow to change parents contract. D does fancy = check for "overridden" methods so that child cannot > change parent behavior. I agree this is correct for type safety. >=20 > Since D is strongly typed, D has "overloading" and D user can get = around with the previous restriction easily. > e.g. foo(x, y) in class B will ignore A::foo contract at all. Same = applies to type difference, since this is what "overloading" is. >=20 > PHP is weakly typed. There is no point follow D principle for = "overridden" > methods because PHP type > is weak and PHP does not have "overloading". >=20 > I think this answers to your question. I think you misunderstood me, I did not have any questions, I merely = wanted to explain to Fran=C3=A7ois what LSP means, but thanks anyway :) I am not sure how easy it would be or rather how much performance impact = it would have when we try to enforce LSP for DbC. I think it is not = feasible for PHP. So I would say we leave it up to the user and he/she has to make sure = that LSP is not violated. A static analyser could still help the user = and point out LSP violations, I think that does not need to be part of = the language. >=20 > Regards, >=20 > P.S. Are we really going to consider strict type safety for PHP?? If you mean strong typing for PHP then no, certainly not.=20 >=20 > -- > Yasuo Ohgaki > yohgaki@ohgaki.net[Robert Stoll]=20