Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126388 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 6FC861A00BC for ; Thu, 13 Feb 2025 10:21:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1739441953; bh=YeDbtKPEIg1xqEQej+gpD8N3H4L7Gjk5UFnEl43utLE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=mCj+YPpfX4iJjNaMJIXIoyWSiTTS/5iDQGDaQN9QHJj/ixHD0mtvCdndkNujjZHuX 2yGbeLK7KYxNsRvpGNsV0a7hudX0b2UVQ2jh3l0c3K9ELOJBO3l3PnMx+ftzBZ/ifS KtquaRKZvWPMaXw2zeeq83yKAR04BPTqzvVGw6xgdvK1WARsZvz9Th4fXaD3t/F0cV vYAhzEhlNL33n0GcAMWr6/AY5xpaSbWVA+Nr3/BqkwVQYJMUGNnY10HELIXMsuC0WP 2wLRdtFCiBEpS9BjimTwU8lmo/KWpLuk0RiY+rfMRqYwzrjS04dwncOFyWNEoEZNod EJK+5VPezNN4g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1E774180048 for ; Thu, 13 Feb 2025 10:19:12 +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_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, 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-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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, 13 Feb 2025 10:19:08 +0000 (UTC) Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5de47cf9329so1075319a12.3 for ; Thu, 13 Feb 2025 02:21:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739442110; x=1740046910; 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=ifCGJKA3Hfw/tFe5JjzcksH1bjAYy1DIa6J6wi/hOwI=; b=VKlLLyu8/uaadHsrCt+PD3M3w60/b1WlwjEPdDI48/6Q6ohNOacbDk838X+oI4B01/ cJapRgAeN8H1I22G4vvN68vv9/dufhVhy+U8sgsWd6K5JFXtrFqn+xKNSXJ+L+lJ61A3 bONjPaiIXPP3/2zLMp1ftxafmewMtnG8quI/yRrDK3LZAGi7+4ENjqFm+YShtKHivj87 XNki6hP342n9akKeJhTM+OarpDHm97aGJRdFVVv+U5UVSeZu5CBzPLK5QhMD4/jeHnXr 2CfljboLXOO0yydx9H5WxuUi1yLEGyM1gP/SzZqnljhI3RQDka2K8/wHGhx3GzaTzBsI hd2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739442110; x=1740046910; 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=ifCGJKA3Hfw/tFe5JjzcksH1bjAYy1DIa6J6wi/hOwI=; b=wMlqmDncN2zVWK8wh47AgjC8jC1KT0l3s8WPMS5PL7kYIZ28ooMMEfO+XLMx5PzMt9 jHlHVlH+NwSVmlrFDsNGW2P4txQAt7plT1duuq8dfsqO9UCSFMN2380fl7cN4VpGwpUI ECY3VkmXGz1YVuhrufAeMbZJpa4laP6BZp5NEHldaBg24JShyweii2hxPfDWoVec4/uF Fllh9TDUpyhmpHXcn0VSkQxWoWzQGI7pDNV1ZxmneRZFa4z4LjFHfpM/rUt1YGxBXgG7 AyBJH2WGE0U9a1uwUJKzCA7mUoKIs7JKmJgnn1GMmEkmXxKAcsqKjGX8ofkGctBfW414 hbVg== X-Forwarded-Encrypted: i=1; AJvYcCXcr2TnLpwSCTbnmMbArKsNywWThHWKF7lLwNsrQ3AbLqyE9HfYy4hZi7km0099BndC2vwIGl/FTxI=@lists.php.net X-Gm-Message-State: AOJu0YxptCBayNUwZTm0VUrOE8myBrADUlRnxTiebzSeuHVDi+wz8LQM yI0oV8YJVNldiCOxNQhPkfds82EmaoYhVQlstPFFQBULA5ygEYyr43EIJheYVO0Wpk8eOK6XEW2 LWtHT8Azv8RNrGQrXO3mz+vCdWK74F2nq X-Gm-Gg: ASbGncux0P2qJ2JRE5AsuuLuSYXuhWoMlz3qhRIpVYfbxBuyrXEvDJ2+lYcbP5EtJqr YpLDl+u0gz6e4yNOIsLaaABkUnPK+2CkoiVjumJCwzVPGiszqQI0lbca4v+9egF4Zt/b3yA== X-Google-Smtp-Source: AGHT+IG/l6gFOlkFCVz5zr/hx4woSCj8wGCik38oDGsLkYVmi3S1WSLO0heMDsXFtZgXfHcLDb4ac1qLzZbM3pA8gNA= X-Received: by 2002:a05:6402:274d:b0:5de:5263:ae79 with SMTP id 4fb4d7f45d1cf-5deb08813d5mr5314507a12.12.1739442109852; Thu, 13 Feb 2025 02:21:49 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 13 Feb 2025 11:21:22 +0100 X-Gm-Features: AWEUYZnZyk0q8Rl-2hnU56axXPMXDEjCJqFy6XEvimPdZq2iXU5ZBlIpnxw43aU Message-ID: Subject: Re: [PHP-DEV] RFC: Marking return values as important (#[\NoDiscard]) To: =?UTF-8?Q?Tim_D=C3=BCsterhus?= Cc: Volker Dusch , php internals Content-Type: multipart/alternative; boundary="00000000000010b3c8062e036d90" From: kjarli@gmail.com (Lynn) --00000000000010b3c8062e036d90 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 29, 2025 at 4:14=E2=80=AFPM Tim D=C3=BCsterhus wrote: > Hi > > Volker and I would like to start discussion on our RFC to allow "Marking > return values as important (#[\NoDiscard])". > > Please find the following resources for your reference: > > - RFC: https://wiki.php.net/rfc/marking_return_value_as_important > - Implementation: https://github.com/php/php-src/pull/17599 > > Best regards > Tim D=C3=BCsterhus > I don't see this as something useful when you want to force interactions with variables. I do see value in using this for the keeping and closing of resources, but the only error you should ever get is when you use `#[NoDiscard]` without a return value. https://3v4l.org/L4bOc


On Wed, Jan 29,= 2025 at 4:14=E2=80=AFPM Tim D=C3=BCsterhus <tim@bastelstu.be> wrote:
Hi

Volker and I would like to start discussion on our RFC to allow "Marki= ng
return values as important (#[\NoDiscard])".

Please find the following resources for your reference:

- RFC: https://wiki.php.net/rfc/marking_re= turn_value_as_important
- Implementation: https://github.com/php/php-src/pull/17599=

Best regards
Tim D=C3=BCsterhus

I don't see this= as something useful when you want to force interactions with variables. I = do see value in using this for the keeping and closing of resources, but th= e only error you should ever get is when you use `#[NoDiscard]` without a r= eturn value.


<?php

#[NoDisca= rd]
function lockFile(string $path) {
=C2=A0 =C2=A0 $handle =3D fopen= ($path, 'r+');
=C2=A0 =C2=A0 if (! $handle || ! flock($handle, L= OCK_EX)) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 throw new RuntimeException('F= ailed locking ' . $path);
=C2=A0 =C2=A0 }
=C2=A0 =C2=A0 return $h= andle;
}

// what we write
function main() {
=C2=A0 =C2=A0 l= ockFile($path);
=C2=A0 =C2=A0 doSomething();
=C2=A0 =C2=A0 echo '= hi';
}

// gets rewritten internally to something like
func= tion main() {
=C2=A0 =C2=A0 $hidden =3D lockFile($path);
=C2=A0 =C2= =A0 doSomething();
=C2=A0 =C2=A0 echo 'hi';
=C2=A0 =C2=A0 uns= et($hidden);
}

// if we do assign it, we omit it all
// what w= e write here would not get rewritten
function main() {
=C2=A0 =C2=A0 = $handle =3D lockFile($path);
=C2=A0 =C2=A0 doSomething();
=C2=A0 =C2= =A0 echo 'hi';
}

// if we were to ever get a "using&= quot;-like
// what we write
function main() {
=C2=A0 =C2=A0 using = {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 lockFile($path);
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 doSomething();
=C2=A0 =C2=A0 }
=C2=A0 =C2=A0 echo 'hi'= ;
}

// gets rewritten internally to something like
function ma= in() {
=C2=A0 =C2=A0 $hidden =3D lockFile($path);
=C2=A0 =C2=A0 doSom= ething();
=C2=A0 =C2=A0 unset($hidden);
=C2=A0 =C2=A0 echo 'hi= 9;;
}
--00000000000010b3c8062e036d90--