Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97225 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25242 invoked from network); 29 Nov 2016 16:28:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Nov 2016 16:28:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.213.49 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.213.49 mail-vk0-f49.google.com Received: from [209.85.213.49] ([209.85.213.49:36290] helo=mail-vk0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 72/90-20013-CACAD385 for ; Tue, 29 Nov 2016 11:28:30 -0500 Received: by mail-vk0-f49.google.com with SMTP id p9so94614851vkd.3 for ; Tue, 29 Nov 2016 08:28:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=4RqHaeNSckVAr3rVI0ZcnR3CdB7K9S48TKS2cpCA0Z4=; b=Vmad0XgOWQSg1rwVZdVdflcEFX8G8XHI7fNna0wXmw98J0LdOHtSs+anUkphIHj/1T v2RadTcz8SDBSXnpuV7VGmGneCzTq2Bex84MM/RIQhvLdpdfbNIDITog51m/S6is47ja oD7z01pVYoDNt3KPrc3V7oekJyZrAr4KxDx6Ks0O6LJ3RSsqeTxmXqDknF2h/xh7btGE X3GMfrR03EWEHQIyOkRe6tQMtYPh7QNTfEZluuu1fd8DtupndrnOgh8K/Gu8X6+Pxa3T S77hYN57nBZLwtj38qIFbAPL0FtzBgR6+1JKerLnSMrsjyizW4NOkbo29p+XtPzF49Lk IrOQ== 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:from:date :message-id:subject:to:cc; bh=4RqHaeNSckVAr3rVI0ZcnR3CdB7K9S48TKS2cpCA0Z4=; b=bmygeSJnfZETnggPzyXkHWoWtDvOg+8hXxkD5yU8ukBuVQOKjTXcB9HRLTqOjOBPut KvQ02VkbOx3f4lWqTgPk7ZwxnEMempUqTVz67CS+bRMhriGD+Rqo8oYEqrzo0TU1dsU4 /p3/EeFNXV+hnmzfQHP6imi/Stu3jc1YmPNlPgaIV4HWZKc71qhGwJEarxQBbcWTTXC0 M0/gJqzW2DwyiqSbxQzpcLg6adwgyUvOg/oeR0DJytdeGoiGGcQDUsQL5zozXfw0FhdG vOYNxKhDuSMs/sDba3yX3S/UowP4tS8K7CC466ZRQErTKwtptMMgyYSdHK7kBn/xfgWq 3r5A== X-Gm-Message-State: AKaTC03DRd/7iiXgjbffA7Tt01kBtQ542UycgNbjsOqjotZi8GaddsgPMdkw1huzIQjD1le2ShAX2Rd5TyGLpQ== X-Received: by 10.31.82.195 with SMTP id g186mr8774525vkb.74.1480436905941; Tue, 29 Nov 2016 08:28:25 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.88.9 with HTTP; Tue, 29 Nov 2016 08:28:25 -0800 (PST) In-Reply-To: References: Date: Tue, 29 Nov 2016 17:28:25 +0100 Message-ID: To: Niklas Keller Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a114e3494e435dd0542731318 Subject: Re: [PHP-DEV] [RFC] Parameter No Type Variance From: rasmus@mindplay.dk (Rasmus Schultz) --001a114e3494e435dd0542731318 Content-Type: text/plain; charset=UTF-8 But this leads to code that can't pass static inspections? interface Joiner { public function join(array $array): string; } class WideJoiner implements Joiner { public function join($iterable): string { $array = is_array($iterable) ? $array : iterable_to_array($iterable); return implode(", ", $array); } } function joinWith(Joiner $joiner, $iterable) { return $joiner->join($iterable); // <-- invalid argument ? } According to the Joiner abstraction, only array is accepted, and that's all a static analysis tool can know about the $joiner argument in the joinWith() function. Being unable to pass static inspections is one thing, but this also makes the code generally difficult to explain - there's a contract, Joiner, which states that an array is required - to a person reading the joinWith() function, that's all they can know about a Joiner instance; it isn't safe for anybody to depend on a specific implementation of Joiner with a widened argument-type, unless they read through the entire codebase and happen to know about the WideJoiner implementation, but even then, someone using the joinWith() function would also need to know which implementation of Joiner is being passed, which seems to defeats the purpose of even having an abstraction in the first place? On Mon, Nov 21, 2016 at 10:39 AM, Niklas Keller wrote: > Morning Internals, > > I'd like to announce a RFC to allow omitting the type declarations for > parameters in subclasses: > https://wiki.php.net/rfc/parameter-no-type-variance > > PHP doesn't currently allow variance for parameters as checking these for > compatibility isn't possible on compile time. > This limitation is caused by autoloading and doesn't allow widening the > accepted parameters. > > This RFC proposes to allow ommiting the type entirely in a subclass, as > dropping all parameter constraints is > always valid according to the LSP principle. > > We already allow return types being added in subclasses. > > Your feedback is welcome. :-) > > Regards, Niklas > --001a114e3494e435dd0542731318--