Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127963 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 lists.php.net (Postfix) with ESMTPS id 88FDA1A00BC for ; Wed, 9 Jul 2025 06:48:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752043585; bh=dq0MCs+HIaMcZa9C+F8rB3+aaWXCsmEwp2nnZg2CJe0=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=VfEcvGDQJu+DceIQKAJH03I9rn5PfbwGybXSxouXORuacuIYyGKDsyEu96wjVkhsd 4dr4vbYhexTcIB/IVxc5rod6hMefkvFjx/NpWqswG9vTBD0Poavo3kd75BFouBvSTL GJvmNthuqVzJmllLHkQ6My1bxVfYXQ+Uo1O2dU/pmPI1k4PiP1022dhAg5tKY9bBMq TeKq1cxkQiQ/ylTrd1tk5u52RfHd+LRQ5TQjdVczo2bv6pMYlRrM0c8vrbIUBFQGeX iYF/aChCIBMkTIx4j13W/l+rbvmAzhoHQrnd0Y9eg8RMcECb3I4N+3G6/gwOaRdmKL F9hPpyS1VSD2w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 44E78180053 for ; Wed, 9 Jul 2025 06:46:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_20,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.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 ; Wed, 9 Jul 2025 06:46:25 +0000 (UTC) Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3a588da60dfso3528099f8f.1 for ; Tue, 08 Jul 2025 23:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752043694; x=1752648494; darn=lists.php.net; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=jjrEU+Nlg/P7pLBTFxgeWwLcHuDviOh4E0LPKfk8nfk=; b=cW430ojvTWTzpbpANA3AABynqbYJ6snFCJnmsr67+DyL2FgwICxdp1dL/3ZC29a1LM GpoqNronfgQImcKpySwFQpMNz9Wr8QO/pZxCjUugndXuumk7u7AUtzHHFrCtbIvy4pTR DPif5viCnUf1pwDRBdMf2JXMRZBK3mf6VzluU+hl3ZRf2P7/g6HsgRKdI1Y67n2nehKO gtBJ2//DGQHhkid/51Y+kgOHdae+G4cf8FpRmZ4ZzQoajByJSDQXXxef/Om+Z2a57WFo 5jDsCQ58HukXrNzM3bp8E4yhjS3ela+Xy53K5Zmk6XJ604GyuwtUJj5pYwfGAzxASzo9 D6Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752043694; x=1752648494; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jjrEU+Nlg/P7pLBTFxgeWwLcHuDviOh4E0LPKfk8nfk=; b=YgRw+xs0RG7dwHER8uDHRSv+/oJg9nvBpAlGYUO7IQzhavae41oIN9L/MBxesKahDP e2DMU9OHGW0ZkXFvZEQA5DAcNi6wBg4+I0x0+9DmV6BMFvihAx0fF736O3Ky4egcIcP0 i9FOT++TjgPXUQIP4s+7+femGTT4pxNfsm+EY4TLZ/wi4PssTCVa1xZ74n/+r19U/y4q vKNzT9q3n/tUAV7kOk+i/ofaf88uEO5XQ4DC4Jt32/YPqzyG/MMof+bV/akFw8tKAOuB fiWxSp4F+nVoSv7pJwk5ATyxQtpi4BvdeP0K38VO/IOoB4t9pqOCcSvCd3yGdlUuXe0R 5ULw== X-Gm-Message-State: AOJu0YzZXB56/QP1E1vL8oCVb0tI0OQwbc/G7fJMkOTysauWfDQpWoSz D5wIJELsf9cRgNccl2qc7lvMG4tktcdonWt/LiXeHYmrEXgLkSTSMELv X-Gm-Gg: ASbGnctOw9uJX7FUCnTNVRliviPelo6xuzUd+FQ/Uw6k9IRwcTXUCLT/jyndkHTETIO /sBzSC6i3zUIFACl1OOIhpas/OaMfTUkkHMaD6IwtxdvYPBx7yc1PLC3xodHxGShXfGiyrAXTOz n9ymYeeqpv2FU8g01tDw9IcGBhbvr5EjS5o1sytd6CMqrIDqhkMDTAExrSD2wyutAH3KDTRELgQ sR02BQojYHR8lALdu5pLSLMqGr0HjY1foFJJLGm7oR8XP0oKVtvjib0e7Jw9EsbBkxKrh+TFjV2 +n5gezG9BbtlAt3GH6+Lq8z7HXjQeq0paMtsaNH38r0cWbpHSoHAgkq7HctguQLvQ7KoKhDN6oF 0TlvmT07I+I46sQI= X-Google-Smtp-Source: AGHT+IGSCPv9q/jUOhzLRhBrlhzEeWveK35uxVpZf30xakdFlCb1JyH7gIvJwkMPA9QpLxTaavDi6w== X-Received: by 2002:a5d:5f96:0:b0:3a5:2b75:56cc with SMTP id ffacd0b85a97d-3b5e4530ea7mr790939f8f.23.1752043693843; Tue, 08 Jul 2025 23:48:13 -0700 (PDT) Received: from smtpclient.apple ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b471b97339sm15048142f8f.64.2025.07.08.23.48.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Jul 2025 23:48:13 -0700 (PDT) Message-ID: <50D0F3F1-FA6F-4626-B649-75274F9BD8D7@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_5A3B8916-1474-42E6-9976-2A03CD538CD6" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.600.51.1.1\)) Subject: Re: [PHP-DEV] Deprecate return by reference from never ? Date: Wed, 9 Jul 2025 08:48:02 +0200 In-Reply-To: <686DBC13.4010704@adviesenzo.nl> Cc: php internals To: Juliette Reinders Folmer References: <686DBC13.4010704@adviesenzo.nl> X-Mailer: Apple Mail (2.3826.600.51.1.1) From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_5A3B8916-1474-42E6-9976-2A03CD538CD6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 9 juil. 2025 =C3=A0 02:47, Juliette Reinders Folmer = a =C3=A9crit : >=20 > L.S., >=20 > I just noticed something which seems odd to me: PHP 8.1 deprecated = declaring a function to return by reference when the return type is = void: >=20 > `function &foo() : void {}` results in: > "Deprecated: foo(): Returning by reference from a void function is = deprecated" >=20 > However, declaring a function to return by reference when the return = type is "never" does not yield either an error or a deprecation notice: = https://3v4l.org/DWs7t >=20 > I might well be missing something, but this feels a bit strange and = inconsistent to me. >=20 > Should this be fixed by also deprecating return by reference for = "never" functions ? >=20 > Smile, > Juliette >=20 > =20 Hi Juliette, The two cases are subtly different, and this can be illustrated by the = following example: Suppose you have an interface mandating to implement a method that = returns something by reference. When you implement that interface, you must provide a method that = returns by reference, but you are free to actually never return from = it=E2=80=94restricting the return type to `never`. On the other hand, you cannot implement it with a method that doesn=E2=80=99= t provide a value when returning=E2=80=94changing the return type to = `void`. In other words, although the combination of =E2=80=9Cby reference=E2=80=9D= and =E2=80=9Cnever=E2=80=9D is not useful in isolation, it makes = nevertheless sense when you think of =E2=80=9Cnever=E2=80=9D as a = special case of =E2=80=9Ca value that satisfies a set of constraints=E2=80= =9D. =E2=80=94Claude= --Apple-Mail=_5A3B8916-1474-42E6-9976-2A03CD538CD6 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

Le 9 juil. 2025 =C3=A0 02:47, Juliette Reinders = Folmer <php-internals_nospam@adviesenzo.nl> a =C3=A9crit = :

=20 =20
L.S.,

I just noticed something which seems odd to me: PHP 8.1 deprecated declaring a function to return by reference when the return type is void:

`function &foo() : void {}` results in:
"Deprecated: foo(): Returning by reference from a void function is deprecated"

However, declaring a function to return by reference when the return type is "never" does not yield either an error or a deprecation notice: https://3v4l.org/DWs7t

I might well be missing something, but this feels a bit strange and inconsistent to me.

Should this be fixed by also deprecating return by reference for "never" functions ?

Smile,
Juliette

=  

Hi = Juliette,

The two cases are subtly different, = and this can be illustrated by the following = example:

Suppose you have an interface = mandating to implement a method that returns something by = reference.
When you implement that interface, you must provide = a method that returns by reference, but you are free to actually never = return from it=E2=80=94restricting the return type to = `never`.
On the other hand, you cannot implement it with a = method that doesn=E2=80=99t provide a value when returning=E2=80=94changin= g the return type to `void`.

In other words, = although the combination of =E2=80=9Cby reference=E2=80=9D and = =E2=80=9Cnever=E2=80=9D is not useful in isolation, it makes = nevertheless sense when you think of =E2=80=9Cnever=E2=80=9D as a = special case of =E2=80=9Ca value that satisfies a set of = constraints=E2=80=9D.

=E2=80=94Claude
= = --Apple-Mail=_5A3B8916-1474-42E6-9976-2A03CD538CD6--