Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106545 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96668 invoked from network); 11 Aug 2019 15:33:56 -0000 Received: from unknown (HELO mail-qt1-f176.google.com) (209.85.160.176) by pb1.pair.com with SMTP; 11 Aug 2019 15:33:56 -0000 Received: by mail-qt1-f176.google.com with SMTP id u34so1020677qte.2 for ; Sun, 11 Aug 2019 06:01:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=j6m7nWsb2gZdOQ3CZoex7Ta77ljM9kuJPSpjQhA0W4M=; b=WHYlWXos85HNY2UG3Q/UuBtoYxWO1jic4kvnux3C8GCbFETYFuVfDlHngixY42v9sm DzpVQOEt+uNP4f+QiXXlmB7p6A+gdjhsOJ4WuWkphCqtzvfvHRLwbXGwgky4SvNe5SD0 ONdczxiKkFI8mk8mLxYzFScVU9byu9ETZhn0QM5R8g1FqKUjyun6rad5XeB0VHtBwKPs rYikDAtvlqyalcWhh6lxpZzo9JeoJgCfkTzgnkZGqaGozAVZpDg+BYMopDoV9Q517G64 zT0GmOjpCYyZbnduPttlpS7Xelk0tIXY53XaLTDT+j6aQwW1gkZltN29ZBujW6ezGSt9 GPSg== X-Gm-Message-State: APjAAAWNRWm88LUZ5CsSDsbYjKv7OnoTKr6NyKoyt4hV9ynShEIW51bI yiCaFFhiYvFWe74UUkPHGyboJF8nXfE0R6O33m4RIg== X-Google-Smtp-Source: APXvYqywXcuZu62lRJbfS4/MsNnEDyMT7s/EbvxlR/5HwOsX03XtH6ng6xEZuQK5gg4qsyo3Z8Dgl9P/3ZalMSyj45A= X-Received: by 2002:ac8:5444:: with SMTP id d4mr4609189qtq.351.1565528509769; Sun, 11 Aug 2019 06:01:49 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 11 Aug 2019 08:01:38 -0500 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000b5faa8058fd702fa" Subject: Re: [PHP-DEV] Adding return types to internal methods (PHP 8) From: pollita@php.net (Sara Golemon) --000000000000b5faa8058fd702fa Content-Type: text/plain; charset="UTF-8" On Sun, Aug 11, 2019 at 7:51 AM Nikita Popov wrote: > On Sun, Aug 11, 2019 at 2:37 PM Sara Golemon wrote: > > P.S. - Perhaps a way to the middle might be to introduce implicit return > > type hints. If a child method is implemented with no return type > specified > > on a parent method which has one, then the parent's type is assumed at > bind > > time, then we provide a better runtime error if that assumption is > violated > > in a strict_types=1 context which is the only place where strict > covariance > > of return types matters to PHP. > > > > This is an interesting idea. There's still a BC break here, but it's more > limited and only applies to code that is actively violating type contracts > (that were previously implicit). Imho this should not be bound to > strict_types though: strict_types controls coercion behavior of scalar type > annotations, and nothing else. It should not be overloaded with this > additional meaning (and I don't think the BC break is nowhere near large > enough to justify this overloading). > > Fair. Just trying to tread as light as possible, but there is a vanishing point. > Do you have this in mind as something for use by internal classes only, or > as a general language feature? I can see the use as a general language > feature (see for example the debacle where PHPUnit added "void" annotations > to some methods). The migration problem of adding return types is certainly > not limited to internal classes. On the other hand it does seem somewhat > weird that an (inherited) return type will be enforced that was not > explicitly given in the source. > > I agree that it would be as useful to userspace classes as internal ones. It would allow library authors to embrace strong typing without breaking consumers who are already conforming to docblock types. It's probably worth proof-of-concepting this and making an RFC irrespective of the push to annotate all the things. If feasible and accepted, I'd be much more on board with including return types for internal methods in that plan however. -Sara --000000000000b5faa8058fd702fa--