Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127842 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 4C2F71A00BC for ; Wed, 2 Jul 2025 16:23:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1751473308; bh=qegJIlNQUrBlPQqedDMpFAC2/u4TJCHRIdT42SXexzA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=FZgEVv1NnyEO5O0VjIbMJtXhnDilCLzO1O3+1ycKeix76gMbZ4mEdtuV/F3ldMYwv yQsTQH+xYUeD2mOTbywZvr0hPKElclBJyHj7eSQ361eE62BKuzbo5FI1YcCWKPjceI f8VKPrTHk7wACxWRw1ZZEVbJRofzOrk7goyzIu5ymzvukFhMAth99DhRQzUu+uJ7g8 d38azURmhlXfd7W4hKQYxK+y0vKhG0SxhG2JnOuzso+teWdcBbWmKTMBN2kE9bBJw+ gtKxaSVU80QlKCRl3sYdRD1vchMSjL0B3gQKOq3Oa9XspZBApjkuyU+hSNBXUpA8Zz KTxJ7YO05NQAw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 85F3B180074 for ; Wed, 2 Jul 2025 16:21:47 +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=-0.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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, 2 Jul 2025 16:21:44 +0000 (UTC) Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-ae3703c2a8bso919425466b.0 for ; Wed, 02 Jul 2025 09:23:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751473416; x=1752078216; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=A/pKhn/P3SrHFRgQ7odd2gPPr5ggbzPggF3XlizG/0M=; b=nolpPadjys9nzKTIPDO+7QO0eWYM29qmP1V2zWoWvm75mH+f9e9yV2GiPUGRo2xmPl Y6AMc7nG5kP4fYf4zDQ7lytDJUbAXusgaJbD69GmV6ZMMlygW2xfZHsLw59QmvO1J7FU OSieFTruKsMNZWEmQJx6r4fSRX9f6aHJ38NVK27CIywGG7qYB71ZFTjjqi6/T+1Pm42x M9QHgQ4xnY/3YJ31odlzmCoWw0RAqo+keLLWAWX+v0hmU8wPdlOJcRgyiDLDwpyjIWtt LgDHwjN6Ul4JEamQ2YlJwF7kut7PAGgzZx3FPlq8Y8Jzi6AWcG2iguELUpDR8YN2lM3h +fCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751473416; x=1752078216; h=content-transfer-encoding:cc: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=A/pKhn/P3SrHFRgQ7odd2gPPr5ggbzPggF3XlizG/0M=; b=diwq8UCIAGnfwLV5WrJIbd8eoyVrIfI7Sphdlan3gwxnisrLwcsQ3cnR4se3BwfkZi ID0FKTarWkkzEj8yE6Un7bImyE3ofEMnNudeuMi6VUmL4nh3vGUbedvrieDtCkNNb0CY IFJIgH+Pt6SnXNjTZRHeb6tAbUsm0swD6mOUdk6AQlhgHMxynQsu3SWVcFi73c1Gq65b d0H/G5KHreq9zBBhaKKeFnbVcF7XYBd67iv1AkAJxYicb1aCAxqtmksXEIvd8KMw2lvC eSGdaBr0BF/Q2UuVHoNuJBe1vrgom7gVu3+eObBSP+hgRyVjQ6grOdA688g51BXgnaea fGaA== X-Forwarded-Encrypted: i=1; AJvYcCVVOHoA8Wd0KJlBnJOP4ZzLTZUHmQULFIyYvuWmQLmeZAiBLf8TA9sBPVRB+ekewgA7MtsJwfSDiFk=@lists.php.net X-Gm-Message-State: AOJu0YwhtXb2ehbAbxR5ToW0UuVoL7dv9BK4cItGJi4M6pJbye75kcDe 5mkFBuUl1GIYyofNXBBteyn27L6y2kkP3jPdOpB/C8pfNOvn5BH1CUijSTBMrRswBSe/lpq/62h RYAm0bHpJuko+1UdX90qruttzVj5bxnamuBIk X-Gm-Gg: ASbGnctQJLQl3ayuhwa1eknxLPS9qx5vtyAjjUyvCNZ94y3UrA8gVtNnSZc3ukSbpK2 EWjt9vP9o7n9ardGS3Wnc47s9RMiVwR01KMGL8ZGfKWs5nL0Pcr5YcsvD+F7GhOa504Dmu/8c9A BSlc230K4Tm2Ukw132nd2tFvhAdfJA4Lc6Jd360WEgUdZm X-Google-Smtp-Source: AGHT+IFyfJFNaaQMFaX0nVL/D//vJKei247sQGa72SqlWY5/zCMOVBAouZaLu4bBAoZKfJsewPB+KWDd0q3X3DLKM84= X-Received: by 2002:a17:907:9715:b0:ae3:6708:941c with SMTP id a640c23a62f3a-ae3c2b05973mr339558666b.6.1751473414636; Wed, 02 Jul 2025 09:23:34 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <0be8afcb6da0e8df4a9f1b446fb35bde@bastelstu.be> In-Reply-To: <0be8afcb6da0e8df4a9f1b446fb35bde@bastelstu.be> Date: Wed, 2 Jul 2025 18:23:22 +0200 X-Gm-Features: Ac12FXyr9804XCIoRwpao000pZaQ_CmnsrEUV2_BWdpT7zoOLvQM2mfzXtB9n70 Message-ID: Subject: Re: [PHP-DEV] [RFC] Partial Function Application v2 To: =?UTF-8?Q?Tim_D=C3=BCsterhus?= Cc: Larry Garfield , php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: arnaud.lb@gmail.com (Arnaud Le Blanc) Hi Tim, We will update the RFC, but here are a few answers: On Wednesday, July 2nd, 2025 at 17:05, Tim D=C3=BCsterhus wrote: > I've now had a quick look at the implementation and the following > questions came up that the RFC does not answer (and the tests in the PR > do not obviously answer either): > > 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. The Closure signature reflects the parameters that are accepted by the PFA, not the underlying function (so it exposes only unbound parameters). function f(int $a, int $b) { } $f =3D f(?, 2); echo new ReflectionFunction($f); // Output: Partial [ function f ] { @@ test.php 5 - 5 - Parameters [1] { Parameter #0 [ int $a ] } } PFA Reflection is tested in Zend/tests/partial_application/reflection_*.php= t. Parameter names, and which parameters are required, are defined by the RFC. Currently, a few things are broken in the implementation, including parameter default value reflection. 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"]=3D> string(1) "f" ["file"]=3D> string(%d) "test.php" ["line"]=3D> int(7) ["parameter"]=3D> array(1) { ["$a"]=3D> string(10) "" } ["args"]=3D> array(2) { ["a"]=3D> NULL ["b"]=3D> int(2) } } PFAs do not appear in stack traces, only the function does. > Classic FCC are 100% identical to the underlying function and thus can > just =E2=80=9Cpretend=E2=80=9D they are the underlying function, but that= doesn't work > for PFA. Consider the following: > > function foo(string $s, int $i) { > var_dump($s, $i); > } > > $f =3D foo("abc", ?); > > $f([]); > > How will the error message for the resulting TypeError look like? Error messages refer to the underlying function as if it was called directl= y: 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. 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 > var_dump((new ReflectionFunction($f))->getName()); The underlying function name (like FCCs) > var_dump((new ReflectionFunction($f))->getParameters()); See above > is_callable($f, callable_name: $name); > var_dump($name); Closure::__invoke (like FCCs) > function foo(string $s, #[\SensitiveParameter] int $i) { > throw new \Exception(); > } > > $f =3D foo("abc", ?); > > $f(123); > > How will the stack trace look like? Does `#[\\SensitiveParameter]` work > properly? This is broken, but the intent is to support attributes, so that SensitiveParameter and other attributes work as expected. Best Regards, Arnaud