Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121323 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60623 invoked from network); 15 Oct 2023 12:04:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Oct 2023 12:04:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E13D81804AC for ; Sun, 15 Oct 2023 05:04:56 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (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 ; Sun, 15 Oct 2023 05:04:56 -0700 (PDT) Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-53dfc28a2afso6126819a12.1 for ; Sun, 15 Oct 2023 05:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697371495; x=1697976295; darn=lists.php.net; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=btnVDYGq8+/gTDw0TTzPyELwumLjk/csQWytwS+IWG0=; b=jQCTLcqJfbULunOdtJNQ253CHEFzvIzMp+dR7BD2GxVfC1VO/cPdxvnnXhIUnuIGqH WHB03Efv53m7+EzLFzjRPOcRK+zqoespoUycOaYWMzsuc3oYQZsit0nLw2eDpHjv3/ya qNnkQJ5yeaZs9dU0Of8ap0z8+dgBwnejpBL7asGdJr1l+dTVtBpJJq4BbV/k068fKHmv MoFYH/ZrkX4lMcB/V7y859u/O1WAYzjo3MTdOx3dsFBT+qBOlFRQ7MLMmDLo0n3vWlsq MezdwCxViSpF5isgYwEVqsM9+P/7335ZdiM6oD/00uMf1Bc5FmE7WfaGcTIQWg0byfvB 0J5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697371495; x=1697976295; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=btnVDYGq8+/gTDw0TTzPyELwumLjk/csQWytwS+IWG0=; b=sMa6m1y6C5xtJARfQ9Ruf2VIIdqD+PMgUm06W0xK+cwHNoXww2Y8xqDonk3yV+euvb B6KFLfCKf4+KTx17sGocOZmbk2FZZ1v+Zbn+ycFEMAMYWha9MfIcN8O3TLJ69LhTC4LN c9TJYdC8P2/i/4e9LEv7a5s6GTQQ2sJEcoMnj4TSCsQSEuoJj2UlGDJimC8CELHiVd2F W3MyuTGNiE9bSvxlJj9149NtG0Jno7CrKFqCW19H8xXXmkw+VfdVshkIOUDRE3KtxFbr MaCKfJkHOcDsgdRaRCFzdwcqfh0RKZ5bzIRNFE/ezrIEUR9WJ4uFuM+e2Gvrq4rtq0Cm 5ILg== X-Gm-Message-State: AOJu0YwJspw6a4iLChmDxZpBhf3+cEYqZgjCysR61Mqke72vAMv5rfyu 5KSXjGhC12Xz2DYzKi/Do6+vzjq270k= X-Google-Smtp-Source: AGHT+IEqoPlTWdWt58mM8sRzzTxfjAeg8f7RPQhf04AMZv4Bhlbs/c543PPOCLIZr3O757GHVFCDjA== X-Received: by 2002:a50:d714:0:b0:53e:2e0a:f5c4 with SMTP id t20-20020a50d714000000b0053e2e0af5c4mr6171768edi.28.1697371494680; Sun, 15 Oct 2023 05:04:54 -0700 (PDT) Received: from [192.168.0.59] (178-117-137-225.access.telenet.be. [178.117.137.225]) by smtp.gmail.com with ESMTPSA id bt8-20020a0564020a4800b0053e4783afbasm3143611edb.63.2023.10.15.05.04.54 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 15 Oct 2023 05:04:54 -0700 (PDT) Message-ID: Date: Sun, 15 Oct 2023 14:04:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: internals@lists.php.net References: <0e6ee882-472f-43e1-822e-c156d9048e0c@gmail.com> <75d8452e-23ad-4943-b5da-63fdc85c24a0@bastelstu.be> <6765d47f-7f6b-436e-b2c9-d98f675905b0@gmail.com> <055fd91e-743a-432c-a5ad-384a4b0f1f50@mabe.berlin> Content-Language: en-US In-Reply-To: <055fd91e-743a-432c-a5ad-384a4b0f1f50@mabe.berlin> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] DOMXPath / XSLTProcessor function callbacks From: dossche.niels@gmail.com (Niels Dossche) Hi Marc On 10/15/23 12:53, Marc wrote: > Hi, > > On 14.10.23 13:54, Niels Dossche wrote: >> Hi Tim >> >> On 10/14/23 12:30, Tim Düsterhus wrote: >>> Hi >>> >>> On 10/13/23 00:39, Niels Dossche wrote: >>>> Please let me know your thoughts. >>> What does calling ->registerPHPFunctions() do when it's called more than once? Will the existing allow-list be overwritten or amended? >>> >>> i.e. >>> >>> $xpath->registerPHPFunctions([ >>>    'strtoupper', >>> ]); >>> $xpath->registerPHPFunctions([ >>>    'ucfirst', >>> ]); >>> >>> will I be able to: >>> >>> (a) Call ucfirst(), but not strtoupper() >>> (b) Call both >> You can call both, it's additive. > > As it's not clear what these functions do wouldn't it make more sense to introduce new / more clear functions and deprecate the old? > > Like: > > ->addXPathCallable(string $alias, callable $fn); > ->getXPathCallables(): array > ->removeXPathCallable(string $alias); This would be the cleaner option. The question here is how they would interact with each other and the existing registerPhpFunctions(): - addXPathCallable() when the alias already exists: I guess throw a ValueError - remove and get should likely also act on the functions registered via registerPhpFunctions() - What should happen when we call registerPhpFunctions() followed by addXPathCallable("foo", function ($...) {...}); Probably both global functions and foo should be callable. But what should happen then when there is also a global function foo, which one should be called? Probably the explicitly registered callable? What's currently also weird is that in the following snippet: ``` $xpath->registerPhpFunctions(); $xpath->registerPhpFunctions("ucfirst"); ``` then only ucfirst() would be callable, which is surprising especially considering that calling $xpath->registerPhpFunctions("otherfunction") afterwards will make both ucfirst and otherfunction callable. > > And is it really necessary to be able to register all functions? Also what would happen in this case with functions included later? Would they also be callable or only the functions known at the point of registering? > For the first question: unlikely. For the second question: they would also be callable. >>> Best regards >>> Tim Düsterhus >> Cheers >> Niels > > > Best, > Marc > Cheers Niels