Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122367 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 92964 invoked from network); 14 Feb 2024 11:47:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Feb 2024 11:47:11 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1707911232; bh=W8k/YyYeUjl8QyRA4vDLVjvk9L8Ga+CLCEf14wlPUOU=; h=References:In-Reply-To:From:Date:Subject:To:From; b=KeC/0hfwe7cdhJoaq0xdB4htx3a33Du2n0H5VXWOCe7O1dz30kqxAdUFy7+D7qS6k 2fRdy6b0wahVSr/2b5+1VBMiftL9SBhJwiDmXn2QpoVGt4BXnC92XOTT7+HCNEhBWm 2jjP+qRqPhMIpQ2KFms0q69MsFhydmy4+cazGjdujhIiSdSjDeQwdh/O5PnIHiaM25 vTzWhSoDt1ZHDHh/5aq3yLW0SeWTFLQQZdM0DNYkjFwaxcIfrQ6Yg9/Z8AzDaQH+t5 uK3YaDxwDJ0UNA6iEY2OmCz/6EFUIzGBtnI8hWxa77E7r+ho0U7ytfWrVE1TZ7y9KB /e/4xBfkfPXrQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 52A2218070F for ; Wed, 14 Feb 2024 03:47:10 -0800 (PST) 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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) (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, 14 Feb 2024 03:47:08 -0800 (PST) Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-68f006fe28bso3467496d6.1 for ; Wed, 14 Feb 2024 03:47:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707911227; x=1708516027; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=W8k/YyYeUjl8QyRA4vDLVjvk9L8Ga+CLCEf14wlPUOU=; b=InsQI9FXNExcwrVqA5tK6AOVGhju8IQawvcf1Chre5hNcWDe0jzL5gTVRsIhNbfl7S 8z40OQUh9Hraqv35LUKORrPudRHF06gFEzgeebCwjyYet/NC9uuaal3J62Hait0XiK2/ ippP+OuhBmGBcM1uwUJEiobzj4pqjlq0N/benNg7X2er0DTVfr9gSPxjt6fKxnfwnX0K KH6H93vHy7viNLBAYgMELE9j3B6EqVKN0U5axgWQD9YxgvdGIhD0KRoOoJD9p30TDk4J CkzIJmLAT5bwk9BFl5zIN1ytEqmiZNhxxq7azuC1BZ8tZs6j6vdKvz/SVqaA5p7HC2+s wW1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707911227; x=1708516027; h=content-transfer-encoding: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=W8k/YyYeUjl8QyRA4vDLVjvk9L8Ga+CLCEf14wlPUOU=; b=MDLDLIArsKnpVNbs0gbWhTsSfwwEMnln7CN1xMOfaoAn/sKX52feRLtEIiOTsqyUyj Z2EA4Fw2VrikmWOt+KvHm85NCoIh3bfZyJaUKGgLHjqCzMf45SR6fG3PAQEjO9/uzCVr 91dpc6DPDA6I4Ou2usXJdeHIiMzAMd50uZNN2aMK3Nx5ih4Hq563H4JuQZdAZV/RyXj4 ruUPNb/AN2QmoiKoY4E+s7Xj4v4b+q72ymQ8oaUmvHKnLiNGaqE0wdHajTbDLWbjDNHF 8pNrX5nNQU8DJFyNsEQi5EXlfaoZTaKf83dEZh5e2TIwxPH6V4Pp2IVFqfW1HdZwGa/X Y77Q== X-Gm-Message-State: AOJu0Yy4yAGVZWAafDLz8Cw7XnjlCLhjo55jDi1JyLD4DBaB90zm956O 3s62UgBVcoJZGuw+SnVdz9rKwGEzjXcZPbQ4+TYROz7f74SD/KvP8/EPHqOePUVUrsCCJKRXctk gQ9WbLGsKfZQbGKxfJXYUhQUtL27rwxZhXSptHA== X-Google-Smtp-Source: AGHT+IE+N4nXlYJaIPwxsyeFhPLSSTroMsKBVAIUcbYL17SHCyP1uxzsYOyrdj82kU50/EGlRcF+3v188sbrL07n99U= X-Received: by 2002:a0c:e085:0:b0:686:9e8a:a695 with SMTP id l5-20020a0ce085000000b006869e8aa695mr2177176qvk.17.1707911226904; Wed, 14 Feb 2024 03:47:06 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 14 Feb 2024 12:46:56 +0100 Message-ID: To: internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [Discussion] Thoughts on casting to null From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Robert On Wed, Feb 14, 2024 at 1:29=E2=80=AFAM Robert Landers wrote: > > I won't be the first to say this, at first glance, casting to null > sounds silly, but short arrow functions must always return something, > by design. That's when casting to null makes any sense at all (that I > can think of): you want to write a succinct, short function but > guarantee the result is discarded. Instead, if you really must use a > short array function, you have to do something even weirder: > > EventLoop::repeat($pingInterval, fn() =3D> $client->ping() ? null : null)= ; While (void) $client->ping() would solve your problem, it's not very useful outside this scenario. I think there are two issues you're implicitly referring to. 1. Arrow functions cannot be void, because they always return something. 2. Arrow functions cannot contain multiple statements. As for the former, PHP actually had a similar issue for never closures that was solved a while ago [1]. In the report I suggested that the same could be done for void, by making void arrow functions evaluate and drop the right hand side of =3D>, and always return nothing (i.e. null). This would solve your issue, although probably mostly by accident (because void functions return null, and your caller expects exactly null). Regardless, I think this change would be useful, if just to signal that the return value of an arrow function is not intended to be used. The latter would require some sort of block or grouped expression. Short closures have been discussed extensively in the past, so I won't get into that. There's also the comma operator in some languages like C and JavaScript that evaluates a list of expressions and returns the result of the last one, although probably not universally liked (i.e. fn () =3D> ($client->ping(), null)). [1] https://github.com/php/php-src/commit/f957e3e7f17eac6e9195557f3fa79934f= 823fd38 Ilija