Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127995 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 138D11A00BC for ; Thu, 10 Jul 2025 13:31:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752154197; bh=HxrTCBnrCYd5l2JPZSZlKxdPrW4Td9kxQe4pQxIJZKU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=nyKE9bi+P2pGZkrOP756wiILGJMaBskdbdW081A4N3+vJrlJEKs1xtPV4QSs/XkIJ 5NZljnJdsrbbFliI05aZnkKLk/1hY1MH/yxK1edkYX7q/+52ZLuyaxzzEOHN2mk0AD 77r8+kWufbzFlVHwzRXfjWn95V8cSeQhy5399eF/Pl6k4TPm+g1bbXTKs+UdWr7f0a +qu1NNZaU5K2lCObvdvrBLf+uDsAK/m+FGw6U9BGHFbKtPOl91OEq9Q1aXDc74VCTG etF7AWrhwN6FbDx30tpB/EWgsZL47MfMlOYtu3ziUIugQqSTC/pgbgKWAlTECRK2pe NEcFJzxQkG5QA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B2D8F180068 for ; Thu, 10 Jul 2025 13:29:55 +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 ; Thu, 10 Jul 2025 13:29:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1752154293; bh=HmpSFKq63I56ApsZ12M90GwsJTje3ETm96g84s4CVV8=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=Z75zYolxd3yyI99pwSpn7/MiRuZxsqG6bBdnnnR9vpGrwl+hfsdyMGFlNkQ2Yh9rS HzX4evPV4XZIVr7CdeTuoGVUxyCJo2V5yAVBDmoQFb1hZAbvJU2Qo0kdbSwRuFnnw9 jWBiCk5fyfmtW3AU8hzK1yStMuEqXaSoafqhMDRZZKHkxEzbcOiysJAASd/KtaNtPn n3Dc0aWCGxPEUn5tPFrD2PRZWjQpnCGJA8ohCgeBxklXwWuUqkMVn1WaGal5cFJBZc jr+djFHS52jhGmoo1f/F1SWkZLHmymnwfiTnX1HghZDMPjPmQrk/vqneS+LUngT3sL avBgz6POsK98A== Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Thu, 10 Jul 2025 15:31:32 +0200 To: Arnaud Le Blanc Cc: Larry Garfield , php internals Subject: Re: [PHP-DEV] [RFC] Partial Function Application v2 In-Reply-To: References: <0be8afcb6da0e8df4a9f1b446fb35bde@bastelstu.be> Message-ID: <27bb97ffaf593055a93f5d486902437a@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-07-02 18:23, schrieb Arnaud Le Blanc: > We will update the RFC, but here are a few answers: I don't think this has happened yet. > On Wednesday, July 2nd, 2025 at 17:05, Tim Düsterhus > wrote: >> How will PFA calls appear in a stack trace and how will PFA Closures >> look like to `var_dump()`, Reflection, and to observers? > > PFAs are instances of the Closure class (like FCCs), and will look > like a Closure to `var_dump()`, Reflection, and observers. Yes, that was clear. > The Closure signature reflects the parameters that are accepted by the > PFA, not the underlying function (so it exposes only unbound > parameters). That makes sense. > Additionally, `var_dump()` exposes bound and unbound args (with the > value of bound args). Currently the `var_dump()` output looks like > this: > > object(Closure)#1 (5) { > ["name"]=> > string(1) "f" > ["file"]=> > string(%d) "test.php" > ["line"]=> > int(7) > ["parameter"]=> > array(1) { > ["$a"]=> > string(10) "" > } > ["args"]=> > array(2) { > ["a"]=> > NULL > ["b"]=> > int(2) > } > } Thank you. I'm not sure if I like this, particularly the `name`. Compared to FCCs saying that a PFA of `f` has the name `f` is misleading, since the parameter list is different and thus functions are not interchangeable. Instead the name could perhaps be `{partial:f()}`, similarly to the new closure names? > PFAs do not appear in stack traces, only the function does. This would be consistent with `__call()`, but similarly to the above, it could be misleading, since the parameters shown in the stack trace do not match what the user has written at the call site. Would it be possible to insert a fake frame for the call to the partial or is this prohibitively expensive? > Error messages refer to the underlying function as if it was called > directly: > > Uncaught TypeError: foo(): Argument #2 ($i) must be of type int, > array given, in test.php on line 7 > > The line number refers to the call site of the PFA ($f([])), not its > instantiation. See above regarding the stack trace. > However, since PFAs must check argument count before binding them, > errors related to argument count refer to the PFA itself. Currently > the error message for $f() looks like this: > > Uncaught Error: not enough arguments for application of foo, 0 > given and exactly 1 expected, declared in test.php on line 5 in > test.php on line 7 Yes, that makes sense. It's probably not necessary to indicate where the original function was declared, we don't do this for other errors related to the signature either. >> var_dump((new ReflectionFunction($f))->getName()); > > The underlying function name (like FCCs) See above for my `var_dump()` comments. >> is_callable($f, callable_name: $name); >> var_dump($name); > > Closure::__invoke (like FCCs) I changed that with PHP 8.5. With PHP 8.5 `is_callable()` is consistent with ReflectionFunction::getName() for FCCs. See: https://github.com/php/php-src/pull/18063 Best regards Tim Düsterhus