Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126367 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 694091A00BC for ; Mon, 10 Feb 2025 17:04:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1739206885; bh=wAwjsE8qZ6QDrdWj6su81F5D9toW2HiZt9hClsm760I=; h=From:Date:Subject:To:From; b=XPmS8EeHJ3UZllU4zo7882r+5jY2iNEh42ndXyyrfWa8NqP+ubKnEg3UcA6JdVwOH o2Oukg3KVyKx5k8szOV2r83xIvCW7PUnKF8HCMNIMKGPx3p/2KX/Wq4//XfBJwp9ig Qp1c2eJpamHfhuIsuLoG8oWtQY42zZMvu1J8kWgSBDFZ2KGnPDG0/i/NRiS4htapSk TR5yAKHjv0QJYhXQIibbsiMj3CcG66J3ceKxcMlrEWbOdEy6XHjv98mWSoL+gcFJYs Y3CEpRPcBsJWevwwVuH12mwMwBpb6E5kieSvHdBPBDRyygf27cO+6TgJ2tJQc/YcwI J+oe0u2bvdpuQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8BC10180050 for ; Mon, 10 Feb 2025 17:01:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: <91liahim@gmail.com> Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 10 Feb 2025 17:01:24 +0000 (UTC) Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-e573136107bso3954573276.3 for ; Mon, 10 Feb 2025 09:04:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739207047; x=1739811847; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=ayKmLKAabGpgPUjovWLfkl0DZesf3rrZZhmxOsLwwSY=; b=V9Zi4pGxWkNyWKU7wqzvCD/o768NIhC7HyiXMYKFO8MfILYJzRCwSpYlILgRzWANUG 0u68SmESzgcLlLMD5Fhjr3KvsTAtuNDh0OzyG9K94TeI0S8BYsKj9P7ZST4kO9huV5XH 9t/C7NbdURgyfbZSHxYl58ropHyofLQxo+0wIxyTg/4ThSa3JnOcifH5U4dqP+U3nLq9 p21DXV7o6OuR/WAt3BEZn2a0bwe2gyBGJ/cG1p2UgGxHmfVglSXYFTvxxY3Cc94tGGgA HWOVf2aRibiGZve7jF3/Y0mFhDJvPJUmBxpw3Zw/PW05xirw0dI6H7TagZrVsB+5bZn+ u8KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739207047; x=1739811847; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ayKmLKAabGpgPUjovWLfkl0DZesf3rrZZhmxOsLwwSY=; b=NJZIsKUTc8wAsFaEiy4TxOfgBHiUtYZX9CHNXS4/w9osL/2RvHQZT06oMkb30dz0fF 9WWUsZM3WPmbLqNIIrQAwQCaqFgtBdYQ0FG+DxVUiI6yvlFPkMjfw0VYWalpo0UbZ2zm ipdblamCR6ApU+ak3+J3DtqjBCn5ohSDhhKY8AELgZuWpNQrg7PYw0zvwP34l7rtLtgJ O5EWCGg3Yk0vr+QAzqVRQzx0RhsB7Eq8bG3fpEfDpgxk9ZTBJJItNPMc2gHka0iqCkbs Ryj4G9dbL/qxI2e5k3dcUG4jYxvNrHQbNsDRIUtcGYnNV7l/aBkyr7Fjgjg2mnKvp33O EiNA== X-Gm-Message-State: AOJu0YxErpL27+AnHloWCf98cgNF8hiKVXv4LrHydLChRjwyGxAssAyu qdejTQXzJrxduKgdC3ZmIlZgbMeLOlWZau9p/mIV0GAJI6Ory9S/mrHYzGcIw8uH3TNaWmh/FGx al/cIfULKW2aZt6rhWXJW6aPrSPs0jDE4 X-Gm-Gg: ASbGncteXRyXQL6KgrDWZT/E+SbC+Cuq2Q96bF8VMvSXldxaokBHXAQN0Tq2cYlgVNx nhUeNsYgoUolk4Y6rxYjNzASsn6h58+IISfoOpoOW5fthez9mnYXC/uCFl2cGGTx1kvZ67gtw X-Google-Smtp-Source: AGHT+IFgBVu1T+F8ZArZzvlvQd+Uw4Gbs29w1T7aqNfNT1IRhBzvE2bomLzEGy1SiGgoyH0Nmp7fn03G9OKgPeQV5FI= X-Received: by 2002:a05:690c:6f0c:b0:6f9:50aa:b7e2 with SMTP id 00721157ae682-6f9b28d1fbcmr139009217b3.21.1739207046953; Mon, 10 Feb 2025 09:04:06 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 10 Feb 2025 22:03:53 +0500 X-Gm-Features: AWEUYZnnBzAm7DwYhwjriVzJJCyVty57d-EIQSgBVD5hejDGjonEJQwq2SH7J6Y Message-ID: Subject: [PHP-DEV] Override static in return types with self in final classes To: PHP internals Content-Type: multipart/alternative; boundary="00000000000039860f062dccb22b" From: 91liahim@gmail.com (Mihail Liahimov) --00000000000039860f062dccb22b Content-Type: text/plain; charset="UTF-8" After implementing static types in return methods, I noticed one thing that was illogical, in my opinion. We have the following code: interface A { public function method1(): static; } final class Foo extends B implements A { public function method1(): static { return $this; } } It seems to me that in final classes, redefining return types in methods from static to self will not be a violation of covariance, because the final class will never have children. But now it triggers an error Fatal error: Declaration of Foo::method1(): Foo must be compatible with B::method1(): static. What do you think about this? I think using static inside classes always implies that the class can have children. And when static occurs in the final class, it's a bit confusing. So I'd like to see the language provide the ability to replace static with self, because again, it's not a violation of covariance. In addition, the same PHPStorm suggests replacing static types with self types in final classes (if this type is not specified in the prototype). You can read some conversation and thoughts in github issue (PR is already attached): https://github.com/php/php-src/issues/17725 --00000000000039860f062dccb22b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
After implementing static types in return methods, I notic= ed one thing that was illogical, in my opinion.

We have the followin= g code:

interface A
{
=C2=A0 =C2=A0 public function method1():= static;
}

final class Foo extends B implements A
{
=C2=A0 = =C2=A0 public function method1(): static
=C2=A0 =C2=A0 {
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 return $this;
=C2=A0 =C2=A0 }
}

It seems to = me that in final classes, redefining return types in methods from static to= self will not be a violation of covariance, because the final class will n= ever have children. But now it triggers an error Fatal error: Declaration o= f Foo::method1(): Foo must be compatible with B::method1(): static. What do= you think about this?

I think using static inside classes always im= plies that the class can have children. And when static occurs in the final= class, it's a bit confusing. So I'd like to see the language provi= de the ability to replace static with self, because again, it's not a v= iolation of covariance.

In addition, the same PHPStorm suggests repl= acing static types with self types in final classes (if this type is not sp= ecified in the prototype).

You can read some conversation and though= ts in github issue (PR is already attached): https://github.com/php/php-src/issues/17725

--00000000000039860f062dccb22b--