Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127577 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 BCADC1A00BC for ; Wed, 4 Jun 2025 09:23:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1749028898; bh=wrL6RF4oi6PV5PPYARykLAVaFZITQ/d/3JIHPy1Gchs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ESESlMasxv6qdQwZCpIqeFA7+ckGNw5SXSoCpxgG4SnnKqhqHPIpbyilnAfqkDy2X t2tQNsPW/5/bbI1jUm/iV8MXVkorwNHAZu7/en7aHALO7K7oA+uExDe0RsiAE9K7mk DLSFn70ECObDngion+4/cWsL9Vesj8N3XCXpD+NbcLZvKc+lBniljbO5AzZzi6RKeo ivGYnmolNfRGdkewFkYiYAGu8wAJIswko+M6MsBxVVHUJ0AK8HoytSJ6ai4NdnPM6f yMmTnzU4ZGmXSjnVjHaSkEFRJvMpKJdVdrybZmpkYqTDfjjMyk2VbejUqGnWTvgTEF 3tLiTHdmJsWvw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 097741801D8 for ; Wed, 4 Jun 2025 09:21:38 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,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 chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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, 4 Jun 2025 09:21:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1749029019; bh=51x5Muo50bBVrIpAreFmYFfOOC3rZ3Km6BBEYH7+IrE=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=K85ZJ2cp1sxh7QSYXeXAChsf56pr01lEn7eNIMxeb7OIIg8dPPrMtoN9yKR38fW6H z/4NINvB+/218vOjHyGTIKGL3X5kG5u+52MK8XYFwtusVJZhqjh4SCAaykwvv+dujf YekFN6Qkiv+pCPxXxUbJ9zkaO0+/WxJ52ZVcnqDCNT15QG/eFQ7SbIDVQYaBWyDqMe ObI/FNcftYWlogYwlAqsJo6A8YirKmWQyBwAPqpvzE2P4cShp05TNKVR2YwxlQg7yk 11CgMuFFZ3thXTizhkv62cnY6X2iBbFFfEfNpF3QmHhzl4m94Lp36x5tieJEtWU9EM 6psmxY4ke/tuw== Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Wed, 04 Jun 2025 11:23:39 +0200 To: Dmitry Derepko Cc: PHP internals Subject: Re: [PHP-DEV] RFC: Single-Expression functions In-Reply-To: References: Message-ID: <68682212b6cc36ebd775e2504d941079@bastelstu.be> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Am 2025-05-22 11:24, schrieb Dmitry Derepko: > I hope this message finds you well. I would like to respectfully > propose > single-expression functions for PHP: > https://wiki.php.net/rfc/single-expression-functions Thank you for updating the RFC to match the template. I've read through it and have some comments: 1. In the implementation I'm seeing that `$a = function() => 123;` will also become legal (“short closures with function instead of fn”). This is not mentioned in the RFC text. It also raises the question how that variant will interact with variable capturing. 2. An AST printing test in the implementation would be useful to have. You can do that with `assert(false && new class { });` (using an anonymous class). 3. I believe the reasoning given is not a fair comparison. The RFC says that `getName() "Name"` would be the relevant information, which I can agree with. But this is not what the proposed syntax looks like. A fair comparison would be: function getName() { return "Name"; } function getName() => "Name"; And when compared like this, it becomes clear that you are trading `{}` for `=>` and effectively only save the `return`, which to me provides little incremental value. Especially when comparing the signatures from the Calculator example: public function multiply(int $a, int $b): int => $a * $b; public function multiply(int $a, int $b): int { return $a * $b; } I also don't like how the actual implementation is pushed to the right of the line. This makes it harder for me to scan for it. The linebreaks that the RFC states “create cognitive overhead” guide the eye for me. So perhaps we should also compare: public function multiply(int $a, int $b): int => $a * $b; public function multiply(int $a, int $b): int { return $a * $b; } So basically the only thing we gain is the removal of a keyword in some situations. When trying to extend the logic in a function to more than one expression (which is not unlikely for methods), I would be forced to make multiple “boilerplate” changes instead of just adding my logic, effectively undoing any benefit the syntax might've provided. Thus I'm very skeptical that the RFC provides sufficient value to justify the impact on the ecosystem (e.g. IDEs, static analyzers, documentation, confusion regarding another closure syntax, …). Best regards Tim Düsterhus