Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106546 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 1564 invoked from network); 11 Aug 2019 15:56:10 -0000 Received: from unknown (HELO mail-lf1-f43.google.com) (209.85.167.43) by pb1.pair.com with SMTP; 11 Aug 2019 15:56:10 -0000 Received: by mail-lf1-f43.google.com with SMTP id j17so18554280lfp.3 for ; Sun, 11 Aug 2019 06:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tbe6Y+YVj+Y79/7LfAInfAocO+xzq+wSIF8Lj6rE8vM=; b=ZJ6Pq26+AQMFtxEm/jam6CHfoYdZH78FLia5J/at6buy4wuDYuDWQr0ZiS9OW6DCbO 1B5uPUedQzj1Cyvq/pui9kQKmDN4V1yFEy0KRiMN8KCBeOkopiEN114YjslSWfNYZ8BR 7jfbB2IuGb81pD1S5VZlgUQQDMgevUlvMYwzHUu20JRKahLSl3qXXnq0XQPk1hEe6/7k 4cZoxsbac0FNnQhq3NICow3vOkFNP4C1mPJNA4jNiLg3zLsVDgptH36oASx7JX22XMZG qWLG823QiXTOah7yBr2p6A9+ipSxU+tJCnLYbxtlvwnGPYjyqN6nVq15/JQQhxBCmgOW AZcw== 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=tbe6Y+YVj+Y79/7LfAInfAocO+xzq+wSIF8Lj6rE8vM=; b=PTr4+nJgKL3LQU8+Pp9RbdGevgZhwaPiJiNEsJi/IYbGdzJ9cFmm6B5O5vvAQV/BD0 00j3BYzzeNoSxu7sPrdP4fGaZFiaSKGz5QaP/lyoVm3ryUMfm2MkdK/blxGmJOx4JUzX qWVUTjHgX/fWQ+pGCQkYW2dsIyIfsulfd7GLld/EmxH/Uwpcwnv5H12VxHq5wgi8IUVg x67jRF4gXkeLQBQap9sL7JV8rBNzA7crrbUPH3UTTOKTBbGSPBHybim0Uur/hT+LK2V4 Q7HKzUiUK4CK09Lt/NAdwgtpArqel2cadRgDlByWWN91wKOyRVDxP/PjpnJPCgx9fvMa WVdw== X-Gm-Message-State: APjAAAUNWKYj0uDJXePbN1IgIrWXFhiwdMmu4KCZzpoUfR6WOnxsRsCT wKi2SG5uei/K8nnToRth67w0ec3h4989ljEUPI/6sdu4 X-Google-Smtp-Source: APXvYqzQLMULTq4t+6ol1EerEs17usNP9f3ud9bnpQO4ZODKJZAG0Eup4Jkt+m5uq6nyiWakXw+T3mK0cSEuqCz/ZQ4= X-Received: by 2002:ac2:44cb:: with SMTP id d11mr16531565lfm.59.1565529843747; Sun, 11 Aug 2019 06:24:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 11 Aug 2019 15:23:46 +0200 Message-ID: To: Sara Golemon Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000038d27b058fd752cd" Subject: Re: [PHP-DEV] Adding return types to internal methods (PHP 8) From: nikita.ppv@gmail.com (Nikita Popov) --00000000000038d27b058fd752cd Content-Type: text/plain; charset="UTF-8" On Sun, Aug 11, 2019 at 3:01 PM Sara Golemon wrote: > 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. > After thinking about this a bit, this is going to be pretty hard to implement. Currently return type checks are performed using a separate opcode, which means that we need to know the return type at compile-time. At the point where inheritance happens and we know the parent return type, we are no longer able to modify the opcodes of the function. We'd have to integrate the return type check into the main return logic, with a possible negative impact on performance... Nikita --00000000000038d27b058fd752cd--