Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:106539
Return-Path: <nikita.ppv@gmail.com>
Delivered-To: mailing list internals@lists.php.net
Received: (qmail 52394 invoked from network); 11 Aug 2019 11:16:20 -0000
Received: from unknown (HELO mail-lj1-f180.google.com) (209.85.208.180)
  by pb1.pair.com with SMTP; 11 Aug 2019 11:16:20 -0000
Received: by mail-lj1-f180.google.com with SMTP id z28so41543978ljn.4
        for <internals@lists.php.net>; Sun, 11 Aug 2019 01:44:11 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:from:date:message-id:subject:to;
        bh=DxXTaKIZIDzAWIxOpCkIH5zWR55FSwNernbQknsTxWY=;
        b=nSQlKYctFnclrmpw/Gs9EaijWoHRuiUU3RZKXnDvxLggZYkQxJlBFTGc43A+Tc1b6h
         9VmPLPKN5k3cOy+DFdCdie5vC7C60H+lIdkTZilO8IUFHkHWM1nWJFhAt+ry9EgqUBUo
         U47Wj3MYTHxfTel+aBmmAhoAPTQS3mgXkBgi1DdGkAYyCEqjjNyc6k/zhmWXh5a4RD43
         BHrc2fzd1uXDO8RO+tQgs6ed/ffZTRD0RoEWYmr++gYzY3ME3nTMRJWmB9EmuPP0HsPk
         b9Cmb6+HuMWbf8pPPvPnMOI/C9kWJRbaSO2l9ewEjkA4Cp3LYKG3aAA9XlBgNRMZLMBq
         zD3Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
        bh=DxXTaKIZIDzAWIxOpCkIH5zWR55FSwNernbQknsTxWY=;
        b=i9bybXyyST1WiIwCpxKmtnWvMntB6kd6ibmMmbR+dNJqmMIQJcfwlgz6t0mwjVyVRI
         PZ+kwFSe0aVAD7t6/rA9q83wBjCtUqx93e/xoESWVuR02njeAikWDOncyyraMzXTf/Ur
         eoT5xBv0upGZbcHK1tcugeqVn2FS2Jld11GxNrbBLcQAevlu3gMLz67FkoGsXJqnVouw
         SUBFt3qnG4SlF4AIA96Z8OF+Kt/3YOIhGIcW1jmsPYVSwpIxAHyXiKCJ73Ppqs9zSz8h
         EApS4nXTAmqlaHDomLWLaroz/8rDV9UOCdGTWpsqH1xHNA2ALMwcQTkuOLRoPBoWK/m7
         yXeg==
X-Gm-Message-State: APjAAAXYMwYHMDB9LQumwYCKhQOlF77PnQMVZ8Lec9QkwPsU7Dgr64E4
	YsOV2x3AAjXCzhEN0tAb3M5GunMDJH1/OHlNxu0l982u/o8=
X-Google-Smtp-Source: APXvYqzvuoKYJ5RF7ILZpvL3VVY2KGfMkzyYZ3VLviJlmtlDP8Si1tc5/3Df+WGH8oxOBE6VvSqHeix8Qx90tQ6rmQg=
X-Received: by 2002:a2e:81c3:: with SMTP id s3mr6526275ljg.70.1565513050512;
 Sun, 11 Aug 2019 01:44:10 -0700 (PDT)
MIME-Version: 1.0
Date: Sun, 11 Aug 2019 10:43:54 +0200
Message-ID: <CAF+90c99ftVY4KndJAH_851sEAF===4iyUgSqrc3nEsL833BhQ@mail.gmail.com>
To: PHP internals <internals@lists.php.net>
Content-Type: multipart/alternative; boundary="00000000000044633e058fd369a9"
Subject: Adding return types to internal methods (PHP 8)
From: nikita.ppv@gmail.com (Nikita Popov)

--00000000000044633e058fd369a9
Content-Type: text/plain; charset="UTF-8"

Hi internals,

Something that came up in the arginfo thread: We can now add type
annotations for everything, apart from return types on methods of non-final
classes.

The reason is that adding these return types would require inheriting
classes to specify them as well. The same problem does not exist for
argument types thanks to https://wiki.php.net/rfc/parameter-no-type-variance
(which is exactly why we wanted that RFC).

For example, if we add a "string" return type to DateTimeZone::getName(),
then any userland child of DateTimeZone would also have to specify a string
return type.

The good news: Userland classes can already specify those types *now*,
because adding a return type in a child class is legal. This means that if
we add those return types, userland extensions do not have to bump their
minimum requirement to PHP 8 when adding the return type: They can still be
compatible all the way down to PHP 7 (or 7.1, depending on the type).

What do you think about this? As we are currently annotating everything
with types, and we're at a major version, this would be the ideal time to
make this change. But there's certainly a BC break here. (And, for the
record, this is not the type of BC break where P++ or editions help,
without creating a larger mess.)

Regards,
Nikita

--00000000000044633e058fd369a9--