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<string, callable> > ->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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php