Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81840 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94661 invoked from network); 4 Feb 2015 21:03:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Feb 2015 21:03:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.41 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.192.41 mail-qg0-f41.google.com Received: from [209.85.192.41] ([209.85.192.41:46727] helo=mail-qg0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 43/D9-40930-71982D45 for ; Wed, 04 Feb 2015 16:03:19 -0500 Received: by mail-qg0-f41.google.com with SMTP id i50so2589276qgf.0 for ; Wed, 04 Feb 2015 13:03:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=coR6M5vRM81u1AFfHCYjGVheV1vmRA/sfPFml4hkheQ=; b=OftMOYnicPuUvf3mqCYkeE0p5JJp0TsSoB7oTph0J4m/BL3vHHgNO6ZFsfstMcHVpP Pp/EKFndm10WuryCmvgb2CPkv/EKgZicUQ+ubYEleQuHCt3spqnLeajFrSnoSFKQg/Mn qNmGwQSchl1COFOLJEkl0wOXiFAFGsESdIjMqjNqWIdgHocG9vbHqv4NO9usTQH77zi9 5nix02iy53K+Vq5Nf1rywQmP8Zyu8iO7lo57eHASZo5ucux9p5aPujrpwgKJAiaAfmcI TJKL7S0F2Ts4YuHJcGSWTJ+COR8eVikL4Jkodn7yKgGitPA4r28MBsbcZZfUw4iB9m1A T8Vw== X-Received: by 10.224.161.138 with SMTP id r10mr514166qax.21.1423083790830; Wed, 04 Feb 2015 13:03:10 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.229.28.72 with HTTP; Wed, 4 Feb 2015 13:02:30 -0800 (PST) In-Reply-To: References: Date: Thu, 5 Feb 2015 06:02:30 +0900 X-Google-Sender-Auth: V3lBPG0eSW97-KYcSXx38AO-AME Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary=089e014953ecd6d20a050e49835d Subject: Re: [PHP-DEV] Allow dropping typehints during inheritance From: yohgaki@ohgaki.net (Yasuo Ohgaki) --089e014953ecd6d20a050e49835d Content-Type: text/plain; charset=UTF-8 Hi Nikita, On Thu, Feb 5, 2015 at 3:49 AM, Nikita Popov wrote: > Currently we do not allow [1] removing a typehint during inheritance. For > example the following code is not valid: > > interface A { > public function method(Typehint $param); > } > class B implements A { > public function method($param); > } > // Fatal error: Declaration of B::method() must be compatible with > A::method(Typehint $param) > > The above code does *not* constitute an LSP violation, because B::method() > accepts more inputs than A::method(). However we still forbid it. > > This is an issue, because it makes it impossible to add typehints to > parameters at a later point in time. I've seen this issue come up both in > userland code, as well as in a recent DateTime change, see > > https://github.com/php/php-src/commit/8e19705a93d785cd1ff8ba3a69699b00169fea47 > . > > Instead of reverting the DateTime BC break, I'm wondering if it wouldn't be > better to fix the root cause by making the inheritance check less strict > and allow removing typehints? > I can understand your reason. It's reasonable perfectly. Template is better, but PHP is weakly typed language. I think it's acceptable. Since Dmitry agreed to introduce DbC, if he like the syntax, etc and proposal is passed. DbC may be used to check various types or user may simply write code that handles various types in function body. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --089e014953ecd6d20a050e49835d--