Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82720 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27585 invoked from network); 15 Feb 2015 11:07:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Feb 2015 11:07:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; 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:60820] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 95/E2-06835-7FD70E45 for ; Sun, 15 Feb 2015 06:07:36 -0500 Received: (qmail 10438 invoked from network); 15 Feb 2015 12:07:31 +0100 Received: from cm135-167.liwest.at (HELO RoLaptop) (81.10.135.167) by ns73.kreativmedia.ch with ESMTPSA (AES256-SHA encrypted, authenticated); 15 Feb 2015 12:07:31 +0100 To: , "'Yasuo Ohgaki'" Cc: "'Dmitry Stogov'" , "'Joe Watkins'" , "'Stanislav Malyshev'" , "'PHP Internals'" References: <54DAFD32.3000005@gmail.com> <54DB0BC0.20304@gmail.com> <54DBA801.8060403@gmail.c om> <011e01d04802$cbd78ce0$6386a6a0$@php.net> <013801d0481d$d34c5170$79e4f450$@php.net> <002701d04846$50c0d630$f2428290$@tutteli.ch> <003501d0490c$2b242a50$816c7ef0$@php.net> In-Reply-To: <003501d0490c$2b242a50$816c7ef0$@php.net> Date: Sun, 15 Feb 2015 12:07:30 +0100 Message-ID: <000301d0490f$981e15f0$c85a41d0$@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: AQGgxP9HPTh52uHWkGo6jLSeXRdtNAHjmxmHAVkKc8gBfNJbegGHSzWZAVLQRzQCoXlWsAGB4HqFAsDJgekCOAevPAH9iUyEAXhQrm4CanwAQAHshXVfAlKjS7cCnkSLtQKk8KdLAgp4FX0A+MmcAQGuA/NIAiGQVloBonCs1wGrMPaqm/77QnA= Content-Language: de-ch Subject: AW: [PHP-DEV] Design by Contract From: php@tutteli.ch ("Robert Stoll") Hi Fran=C3=A7ois > -----Urspr=C3=BCngliche Nachricht----- > Von: Fran=C3=A7ois Laupretre [mailto:francois@php.net] > Gesendet: Sonntag, 15. Februar 2015 11:43 > An: 'Robert Stoll'; 'Yasuo Ohgaki' > Cc: 'Dmitry Stogov'; 'Joe Watkins'; 'Stanislav Malyshev'; 'PHP = Internals' > Betreff: RE: [PHP-DEV] Design by Contract >=20 > > De : Robert Stoll [mailto:php@tutteli.ch] > > > > 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. >=20 > > I guess from the example above it should be clear why D has > > implemented it this way >=20 > OK. Thanks for your explanations. >=20 > What I meant is that, while I understand the theory, I don't = understand the reason *why* it must be done this way. >=20 > An additional point is that, IMO, It is impossible for a software to = enforce the theory and check that a set of conditions is > more or less restrictive than another one, except analyzing them, = which is far beyond our possibilities. So, IMO, we can just > give it as a convention, which is quite poor. That's why I preferred = to use another logic. But I would like to know if it won't > bring other problems later. >=20 > Regards >=20 > Fran=C3=A7ois >=20 >=20 > -- > PHP Internals - PHP Runtime Development Mailing List To unsubscribe, = visit: http://www.php.net/unsub.php Unfortunately, I am not familiar with Eiffel or D, so I am just assuming = and cannot really give you the specific reason behind the design = decision.=20 Having LSP-safe contracts allow that a type checker has do perform a = conformity check only once and not for each case which is most probably = way to slow and further cannot guarantee contract-safety at compile-time = anyway (Eiffel and D are both statically typed). Considering my example again, this time with some kind of static typing: class A{ function foo(int $x){ pre($x > 100); } } class B extends A{ function foo(int $x){ pre($x > 50); // less restrictive, that's fine } } class C{ function foo(int $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=20 } foo(new A()); //that's fine foo(new B()); //fine as well A $a =3D new C(); //the type checker thinks $a is of type A, does not = know that it has actually type C foo($a); //not possible for a type checker to see the violation With the LSP rule in place the type checker does not need to verify the = function call foo since everything of type A will conform anyway. Makes sense no? But as I said, I am just assuming. Someone familiar with = Eiffel or D can probably give some insights. I totally agree with you that such a check is not feasible for PHP, a = dynamically typed language in general respectively. Cheers, Robert