Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120011 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34506 invoked from network); 13 Apr 2023 04:00:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Apr 2023 04:00:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B2595180084 for ; Wed, 12 Apr 2023 21:00:11 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 12 Apr 2023 21:00:08 -0700 (PDT) Received: by mail-yb1-f169.google.com with SMTP id c2so3392070ybo.9 for ; Wed, 12 Apr 2023 21:00:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681358407; x=1683950407; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=t9yDN1E3klCVCQyUFpPB6ColwkuzBuKuXATCOOHQd2c=; b=jK+1rSzsooq3OeEH6E9YHaMpQ5bUpBMDBYt2VJ1vuqlDyWjiSMlzhPiJY8byPcS2MD IjKGFcZ6rGAWrCvnZERpwtLxteKNtsAYLU+RFzmuxktrEwo3poX3bOxhjBdgFtip839v I/hGqyBmwnjlCLuiSjscaeJ85kw1XfOshDgCYVb98FkrYsmgOxEkokSXAwtWG+nGc8Na B5W1JTsZJYqOCZHgNPk1OMJM7Fb/0YdrXn1Jny3RFagBkXnqE2hyzNbjkask3+GahIi4 MQFFwkb7iVMI19yeEzgWzRAKEGU1CNsVfUIsWSqvDcbCQV8ieMG0kUS5bBCJn2seu33F A4Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681358407; x=1683950407; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=t9yDN1E3klCVCQyUFpPB6ColwkuzBuKuXATCOOHQd2c=; b=d1vjfnWOiFWzoBh7Qt9+D14++LRz8oqP9JM1urA61c5YI/ZfA4uMO+hEgHvLWliElA 0jjgNaqkKOjBvbvieiaAk64PMAfJaI98ri8AZg8aAh6xy+BYfT76pafbFApCJt+8diQi LntiGEI5FAesEaNLArNnUJChkKovO7X1Uvbib2mLISXvSY8jik/230YIJu+RU7KhCPYo KAOXQ5kfAjCcrlcdpYCaVKspTHZHquvB7Tc4KR27zlpT99nTV5pxD4x3RXsEwu8sx2Gq ionPL4QIqm5bBiYM8b+WOaqBe+RDFWssKg9r5wsE3AHzxJ8Rqltn3PZxAPEN0LwihbQV uw+A== X-Gm-Message-State: AAQBX9fJJZAwitCnJ10rlxfAuaJkvSEpMN0+YFZojW50NJjo4uN/pL4n 7wJsZzw4nGORgTc8icRsfeQFmV3FQSyQyszTKxEvvT7MG0ey9w== X-Google-Smtp-Source: AKy350YMENoq7nyC3nHsmVN0cjicThylIo3ZXT2HVbY6SPdfhpTWROMn6QDPRilVL5BDuhu1LJzmoIBpmKL9euB1uHQ= X-Received: by 2002:a25:d1ca:0:b0:b8f:517a:13b8 with SMTP id i193-20020a25d1ca000000b00b8f517a13b8mr570383ybg.7.1681358407260; Wed, 12 Apr 2023 21:00:07 -0700 (PDT) MIME-Version: 1.0 Date: Thu, 13 Apr 2023 06:59:56 +0300 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="0000000000009addc805f92fc26c" Subject: First class callable syntax for instance methods From: zsidelnik@gmail.com (Eugene Sidelnyk) --0000000000009addc805f92fc26c Content-Type: text/plain; charset="UTF-8" Hello, internals! I just want to share some thoughts with you regarding what could be improved in the first class callable syntax. It is already possible to create Callable from a static method: ``` class Foo { public static function staticmethod() {} } $c = Foo::staticmethod(...); ``` It would be a great pleasure to have the ability to wrap the instance method the same way. One particular use case for this could be when there's an array of items and it is necessary to call some getter-method on all of them. ``` class Verification { public function __construct(private string $id) {} public function getId(): string { return $this->id; } } $items = [new Verification('1-2-3-4')]; array_map(Verification::getId(...), $items); // previous line is an equivalent of this array_map(static fn (Verification $v) => $v->getId(), $items); ``` Currently this syntax fails in run-time rather than compile-time. ``` PHP Fatal error: Uncaught Error: Non-static method Verification::getId() cannot be called statically in /opt/scratches/scratch_439.php:21 ``` Please, let me know what you think about it. Best regards, Yeven --0000000000009addc805f92fc26c--