Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126245 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 114BF1ADAA0 for ; Thu, 30 Jan 2025 16:42:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1738255187; bh=sj6XOKeImaiwim+3c7JcEVP/hP3RX2X9YT85+X/G1cc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=iiGgmrf1JA2GaXnDtQM82XUUyfRjbUiJ88DZB1Rdo++hMq1aW8x8dEEvhC2V4UCzJ M2sHA81oARZ4rAswj1SuExeWZ4JQb3zXY1Rf8z37JZpskGfXUJMJL0K0iT4xELpsnd Xzv8p/2pevRu5PcOzbD6pMJleBwNStEI7ZRaWAzeLy2ykh86yAxiLxM8e555Ff2GOY InOqp/gawo/W9/g4U1bHm0hj6E0Z4s5+e6fX59b7DC/VgAAc43kWtkOzbgutOcw+hJ 3N3qevWBT4wAlMMA/uLSx9KmlToNflUryBMn7QsCVdNVSKFm6vym8Mwo8adB31dLJ4 D2YoGFeMCPSUA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5F81B180079 for ; Thu, 30 Jan 2025 16:39:44 +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=-1.2 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,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: Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (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 ; Thu, 30 Jan 2025 16:39:41 +0000 (UTC) Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5dc10fe4e62so1907795a12.1 for ; Thu, 30 Jan 2025 08:42:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tideways-gmbh.com; s=google; t=1738255347; x=1738860147; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ZibcD5X61ghOs+iybeTBjjJcZODdOf8OSW8x2P+0vg0=; b=UFSAt2MSaY8RJAPlN9Tx//fcXSB9hk1mMYixPdJ4cY4rIGm9eacf2DMsxTB6CGOM83 sjk6xK2+IvuvU51NLgXMcb4FwHDH4VxnRrX7ej4Gq/Fyy5dRdxcGqSuIMasILYpjGtwm B99l15g2aQh8iG2auUHYGCyUhnVP7USUBNG2Ibak5isPBuYwwakD+NxzR7IW0/3xz82M lhQLbvVgWT4Uh2AzSxmSxvcZRVIudF9P5qCiFxR7KGxmsClWVTGzEivB7Y/KHtur/gge AxYmmQZyuf9IPSmu8EdhpsmO047opG8T9ViK3CF0mRc4k6mEc/xzgY8olGsQgIvUBbOS O0Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738255347; x=1738860147; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZibcD5X61ghOs+iybeTBjjJcZODdOf8OSW8x2P+0vg0=; b=bBcEH6j6KkWADOsgdJJwMR9crJbVKJ6Dn3WOUcCC0BaAlrdlwYNdUizl7hPX4lS0s8 eD79ZAf1HsPLUN+vNTcbdqiHiBX05+wlpT8ugvIoBNCAb+Bbw5wAF6dm3Ipv5z0Gzkf2 jeL4SFuuYOVEcvNgpHFOfRqmG6Rl9PnSXv3Z1nmCbr8pL0oUC0LsXEHxbANaguf0M4Rn gW7He0CebMEhePVBDVawmdVks2fHP608MpWuxQzTjPmqMYfZdHCXKuNnPHhCRhntcbR+ hN77+9oqS/wj5ZHmLP7XDcB8rYTHiwnT2472sW58py9aZi67dmB69msS2NzZOinqVFZZ xzcQ== X-Gm-Message-State: AOJu0YzZDmMnpB7ChvnXNqb66naw1cVplpzCjRHWwMYnyyU322mzEP3w xP6iMF6nfGcu4GlhQPSsVVLQ/oa2m2Zp5G7L7aWzW8wBk+bIUv/nmddMwsi4Zi9sXMpPz6mxJb7 TCvVhRiUAsKud6Y48f4L/ZYjuJz3OB0u69pNzTEsY084wrmh1a+XXjQ== X-Gm-Gg: ASbGnctCHcaUC45h9//sXyQCzANtM4qqKbpZ8KuFXMEQYnqhIDFbMv+7UjEmajOGUQh WsQ8CqvVVVSQ7nsH2id95rOF8fG/iHMmArNfk0Pjm4rgxdMTfndMLzQmUJiCMMNHk2CKvzs4sgm dO3D5ExRdKgPKG4kJMlQs+dXCeHDk= X-Google-Smtp-Source: AGHT+IEE8F4H0aWl4VAA32fH4CX60YON2/vOvGZrZKZrr0rJbK4ErglD7ZcgC/BNkNE1D7tKFndhsZL8hrVhIL2eySI= X-Received: by 2002:a05:6402:2390:b0:5dc:72e1:63ee with SMTP id 4fb4d7f45d1cf-5dc72e1647cmr2233132a12.6.1738255347201; Thu, 30 Jan 2025 08:42:27 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <78eb6c1b-ad20-4b74-b60b-f79623f436db@beccati.com> In-Reply-To: <78eb6c1b-ad20-4b74-b60b-f79623f436db@beccati.com> Date: Thu, 30 Jan 2025 17:42:15 +0100 X-Gm-Features: AWEUYZnTw1Q-EjjfsDvYkj0UtlEOr30WWjojCVVrm0kbXeLEHtE4sfeQvDvyFKo Message-ID: Subject: Re: [PHP-DEV] RFC: Marking return values as important (#[\NoDiscard]) To: Matteo Beccati Cc: php internals Content-Type: multipart/alternative; boundary="0000000000007fda1c062cef1c7e" From: volker@tideways-gmbh.com (Volker Dusch) --0000000000007fda1c062cef1c7e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Matteo, On Thu, Jan 30, 2025 at 1:07=E2=80=AFPM Matteo Beccati wr= ote: > > I reckon it's a nice thing to have, but to be honest I think handling it > just during static analysis would be the best approach. Also there would > be no need for a (void) cast to suppress the warning. > > We also discussed if this should be part of the core language or something that is only supported by tooling. During the discussion we looked for existing context and at what was said around #[Override] [1] at the time. I won't repeat Tim's point from last year here for brevity, but I think the same ideas apply. Having the core language offer a way to tag a function as =E2=80=9Creturn v= alue matters=E2=80=9D would also allow library and tool authors like Psalm and P= HPStan (free & pro versions) to add and work with these tags. Not having each tool to curate its lists of functions where the return value is considered =E2=80=9Cimportant=E2=80=9D, I think, would be an impro= vement overall. It also enables library authors to suggest it to these tools in a standardized way. PHPStorm (and EA-Extended inspections plugin) also ship with lists of functions they warn about that are more extensive than what we propose here, but they also only work for core as there is so no standardized way yet, that I'm aware of, to tell PHPStorm (or any LSP) about this type of requirement. The `void` cast or the `$_` discussed currently would be a `/** @phpstan-suppress UnusedReturnValue */` (or something like that) in PHPStan. So there are various ways of expressing f this concept in syntax, and we tried to find something that doesn't add BC issues to PHP in any way. There has always been overlap between what SA is doing for its users and what PHP is doing for all users of the language. From type checking (static vs. runtime) to warnings and deprecations, things are both checked at runtime and at CI time. PHP its self is more conservative and has more BC focus than the tools, of course, but I think this is a case where the attribute would help with creating a common language. Kind Regards, Volker [1] https://externals.io/message/120233#120432 --=20 Volker Dusch Head of Engineering Tideways GmbH K=C3=B6nigswinterer Str. 116 53227 Bonn https://tideways.io/imprint Sitz der Gesellschaft: Bonn Gesch=C3=A4ftsf=C3=BChrer: Benjamin Au=C3=9Fenhofer (geb. Eberlei) Registergericht: Amtsgericht Bonn, HRB 22127 --0000000000007fda1c062cef1c7e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Matteo,

On Thu, Jan 30, 2025 at 1:07=E2=80=AFPM Matteo Beccati <php@beccati.com> wrote:

I reckon it's a nice thing to have, but to be honest I think handling i= t
just during static analysis would be the best approach. Also there would be no need for a (void) cast to suppress the warning.


We also discussed if this should be = part of the core language or something that is only supported by tooling.= =C2=A0During the discussion we looked for existing context and at what was = said around #[Override] [1]=C2=A0 at the time. I won't repeat Tim's= point from last year here for brevity, but I think the same ideas apply.

Having the core language offer a way to tag a funct= ion as =E2=80=9Creturn value matters=E2=80=9D would also allow library and = tool authors like Psalm and PHPStan (free & pro versions) to add and wo= rk with these tags.
Not=C2=A0having each tool to curate its lists= of functions where the=C2=A0return value is=C2=A0considered =E2=80=9Cimpor= tant=E2=80=9D, I think, would be an improvement=C2=A0overall. It also enabl= es library authors to suggest it to these tools in=C2=A0a standardized way.=

PHPStorm (and EA-Extended inspections plugin) als= o ship with lists of functions they warn about that are more extensive than= what we propose here, but they also only work for core as there is so no s= tandardized way yet, that I'm aware of, to tell PHPStorm (or any LSP) a= bout this type of requirement.=C2=A0

The `void` ca= st or the `$_`=C2=A0 discussed currently would be a `/** @phpstan-suppress UnusedReturnValue */` (or som= ething like that) in PHPStan. So there are various ways of expressing f thi= s concept in syntax, and we tried to find something that doesn't add BC= issues to PHP in any way.=C2=A0=C2=A0

There has a= lways been overlap between what SA is doing for its users and what PHP is d= oing for all users of the language. From type checking (static vs. runtime)= to warnings and deprecations, things are both checked at runtime and at CI= time. PHP its self is more conservative and has more BC focus than the too= ls, of course, but I think this is a case where the attribute would help wi= th=C2=A0creating a common language.

Kind Regards,<= /div>
Volker



--
Gesch=C3=A4ftsf=C3=BChrer: Benjamin = Au=C3=9Fenhofer (geb. Eberlei)
Registergericht: Amtsgericht Bonn,= HRB 22127
--0000000000007fda1c062cef1c7e--