Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127037 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 08AAE1A00BC for ; Fri, 4 Apr 2025 01:52:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1743731381; bh=HnxRAWLs5KFPf4cpTeiEFa6H0P4FKmtQOZ0rZGQTQxc=; h=From:To:Subject:Date:From; b=oKrikEVYHADq1qcPnOS6mqBNbnwtXRxZixX/fg5/9xWatpTUCCDJwvO6w1oP7ZjsA hhppfDdPIMIa/R1Bi4pYvzeG0zz9C272RF/e6V9Qb8U/GGNTutzrjL0k24rYGeweHN gZ7IaC5IabNO1zce6CAiO6Pxl9uJjoRUrAl2c/vomQ/Bm3PryHgQ1uBTmHlzLL2yRt G3RSMsQOeUKQXPQIBaVqmOLOyw8kS7WIVavNwDC8rlq3bC1ucMbsC4SBWa4c0O5kkg XoJ5mUQgikDS/Lq9W0ZGNTWUnxSdoR6EzIC07Fv0jxZWDU5K3lxJLoTEI7uBpQL8aS aO5Skza8JwkPw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 273DF180079 for ; Fri, 4 Apr 2025 01:49:40 +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=0.6 required=5.0 tests=BAYES_50,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 autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.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 ; Fri, 4 Apr 2025 01:49:39 +0000 (UTC) Received: by mail-io1-f43.google.com with SMTP id ca18e2360f4ac-85b4170f1f5so44977939f.3 for ; Thu, 03 Apr 2025 18:52:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743731525; x=1744336325; darn=lists.php.net; h=mime-version:content-transfer-encoding:msip_labels:content-language :accept-language:message-id:date:thread-index:thread-topic:subject :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/NKiGnE6+3HU8AnSpb2Lri9bbUtqN/sHtgGkTTzQZu0=; b=hv2LlpuyDC9IVBUq4js4HbUnLMYevr7T6ULYFSSirj5ULfqE9KuNWcQTs2cmcr+kjo BGHwKWBSCxec+mBoR8CBZwMa6VtPECJv9KPRvUc0a1BB50bvnxCMjyd5xkfggXK2ZfTr YsLKA4TPFaURjJjyVIiwfbeQHMYYGRu4449qdRNboqLBBNrsYsaV5RHMbR/He734AZWL Btit793z2euFdRqrzHycxyail1FKIYtmwcHDE5Rrnr0uC4BDDA82MQ0VB588eiU+KfiS hKLqcAObooL7Z0OQV/RKmoGmDBJn6WubYoefIvJLk4Ndge5sS5YpB1GCmI1QhWCu0VlU os6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743731525; x=1744336325; h=mime-version:content-transfer-encoding:msip_labels:content-language :accept-language:message-id:date:thread-index:thread-topic:subject :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/NKiGnE6+3HU8AnSpb2Lri9bbUtqN/sHtgGkTTzQZu0=; b=Ugs7vgwvjzugRHmLX91OHVXLr323ZC2kBMkNtpAdv4/SpwRuK88vsYQlCCPbbbAFhq ZelbzHRfaq6Rnr9NugXeMvkq1Iq5xbw9rRFhuwR46jixXl8oRDGikJxiJWIwuK7VUKnK IV3nHGfLIRQPjoHIkmwyfc8VHpsyxNZGuO1LZ+fS7sD5UMG3TmIW9C2KDV+uDJlFNSPV dsOnHMOJci4Stlgm9VYgsf5H0uJOFMZ64eIkVYg+kPvepKn2UeROYlwXIDZA7RzNhRT+ Nqoj+jud7Wrpo4X4kRIernuZ/VjU12BdtHXx/w4O2CJ7/c0bb4uw0czQJwppwo5q2uH7 +j2g== X-Gm-Message-State: AOJu0YwR0/6THJ3UfxMPDtuRoltV5UdA2K7IQXcs+y80zsmnkrOzMhFd ZKXz9kFshdiwN9JwNnLEMjJ5l0ZzXoj4Zrvkz5NIjpm6eFjxLfV9ho1KKk9G X-Gm-Gg: ASbGncs5dcHxMjXpzABhKNXlfwd68GUVaRylUjTC5RkdEjij3onOxEvJhXpfxulHVeA jHBs0/GwgVrF3I59rNtC33les1PdNLHUT9vASPVD+Gazqut/mBvuZjYPJhmzB8Se4o8hCPI/y4j 4oSztePinWuiqCIxtyOHMB1YxleA6aP4VCcMo62spbfC5uRBiZQqnxz5RRFfp5D/pKCmmDVyVXU XzKDvjRlDWEsVzqxWQsacwQ/LBTLYwBHiIYOkn41vEo0JFueTrz6tihLuXs2RLHQunWoNgJjF+M mpk8TbPidz/BaULddEkrx879GZ50Or8/BMZGpBAMy1hpYLAG/wXz41+NQKJ69fMY17LZ0mJPf8j D9B7Il1EQrIzUCQ8dUo4ka1OX51A/zlNMQJFlt5PKMVC3pw== X-Google-Smtp-Source: AGHT+IGSUY3ayvkWmWVG9Sdd444lN1bkqaDU6kQF6+5+h9HEyX4Lq3DtcXcWroufqzflVZzb0EKFLA== X-Received: by 2002:a05:6602:751b:b0:85e:1ee9:1c18 with SMTP id ca18e2360f4ac-8611b4d2e35mr158405539f.9.1743731524826; Thu, 03 Apr 2025 18:52:04 -0700 (PDT) Received: from CY4PR05MB3383.namprd05.prod.outlook.com ([2603:1036:906:56::5]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4f4b5c4a373sm581560173.47.2025.04.03.18.52.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Apr 2025 18:52:04 -0700 (PDT) To: "internals@lists.php.net" Subject: [PHP-DEV] Uniform Function Call Syntax Thread-Topic: Uniform Function Call Syntax Thread-Index: AQHbpQPNKa//VBPBXUi0c0Bxb9EgZA== X-MS-Exchange-MessageSentRepresentingType: 1 Date: Fri, 4 Apr 2025 01:52:01 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-Exchange-Organization-SCL: -1 X-MS-TNEF-Correlator: X-MS-Exchange-Organization-RecordReviewCfmType: 0 msip_labels: Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 From: yakov.lipkovich@gmail.com (Yakov Lipkovich) Hello,=0A= =0A= I would like to gather interest in adding Uniform Function Call Syntax (UFC= S) to the PHP language. In short, it allows to call any static function `f(= $a)` as `$a->f(...)`. The `...` is required because not all functions have = the desired parameter in the first position. Outlined below are some benefi= ts of this syntax.=0A= =0A= It allows for chaining of function calls that otherwise would look ugly. A = common pattern is filtering and mapping arrays:=0A= ```php=0A= $arr =3D [1, 2, -3, 4, 0, 5];=0A= $filtered =3D \array_filter($arr, fn ($x) =3D> $x > 0);=0A= $result =3D \array_map(fn ($x) =3D> $x * 2, $filtered);=0A= \var_dump($result);=0A= ```=0A= This can be written more eloquently:=0A= ```php=0A= [1, 2, -3, 4, 0, 5]=0A= ->\array_filter(..., fn ($x) =3D> $x > 0)=0A= ->\array_map(fn ($x) =3D> $x * 2, ...)=0A= ->\var_dump(...);=0A= ```=0A= =0A= Another use case is for extension functions:=0A= ```php=0A= class Cat=0A= {=0A= public function __construct(public string $name) {}=0A= =0A= public function meow(): self=0A= {=0A= echo "{$this->name} meowed\n";=0A= return $this;=0A= }=0A= =0A= public function lickPaw(): self=0A= {=0A= echo "{$this->name} licked paw\n";=0A= return $this;=0A= }=0A= }=0A= =0A= class CatExtension=0A= {=0A= public static function scratch(Cat $cat): Cat=0A= {=0A= echo "{$cat->name} scratched\n";=0A= return $cat;=0A= }=0A= }=0A= =0A= $cat =3D (new Cat('Tabby'))=0A= ->meow()=0A= ->(CatExtension::scratch)(...)=0A= ->lickPaw();=0A= ```=0A= =0A= For my proposal, only static functions need to be supported, but I don't se= e why non-static functions can't be supported. One thing I'm unsure of is w= hat happens if an imported static function has the same name as a member fu= nction.=0A= =0A= The Wikipedia page has a bit more details, as well as examples of languages= which implement this syntax: https://en.wikipedia.org/wiki/Uniform_Functio= n_Call_Syntax.=0A= =0A= Please let me know your questions, opinions, and feedback.=0A= =0A= Regards,=0A= =0A= Yakov=