# [RFC] [Discussion] Improve callbacks in ext/dom and ext/xsl

- Thread: https://externals.io/message/121611
- Original archive: https://news-web.php.net/php.internals/121611
- Started by Niels Dossche on 2023-11-07T19:32:16+00:00
- Messages: 6
- RFC: Improve callbacks in ext/dom and ext/xsl (Implemented (PHP 8.4)) — https://externals.io/rfc/improve_callbacks_dom_and_xsl.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #121611 — Niels Dossche — 2023-11-07T19:32:16+00:00

URL: https://externals.io/message/121611#121611

Hi internals

I'm opening the discussion for my RFC "Improve callbacks in ext/dom and ext/xsl".
RFC link: https://wiki.php.net/rfc/improve_callbacks_dom_and_xsl

Kind regards
Niels

---

## #121655 — tim@bastelstu.be — 2023-11-11T15:32:35+00:00

URL: https://externals.io/message/121611#121655 · In reply to: #121611

Hi


> I'm opening the discussion for my RFC "Improve callbacks in ext/dom and ext/xsl".
> RFC link: https://wiki.php.net/rfc/improve_callbacks_dom_and_xsl

Some question that I believe are not answered:

1.

$xpath->registerPhpFunctions([
   "foo" => ...
]);

$xpath->registerPhpFunctions([
   "foo" => ...
]);

Is this an error due to the duplicate definition or will the last 'foo' win?

2.

$xpath->registerPhpFunctions([]);

Is this an error or a noop?

3.

Would it make sense to deprecate passing a string as "Future Scope"? 
Simplifying the method signature would also allow to simplify the 
documentation in the long run and registering a string is trivially 
fixed by adding square brackets.

In fact looking at the existing documentation at 
https://www.php.net/manual/en/domxpath.registerphpfunctions.php, what's 
the difference between 'php:function()' and 'php:functionString()'?

Best regards
Tim Düsterhus

---

## #121656 — Niels Dossche — 2023-11-11T16:49:10+00:00

URL: https://externals.io/message/121611#121656 · In reply to: #121655

Hi Tim


> Hi
> 
> 
> > […]
> 
> Some question that I believe are not answered:
> 
> 1.
> 
> $xpath->registerPhpFunctions([
>   "foo" => ...
> ]);
> 
> $xpath->registerPhpFunctions([
>   "foo" => ...
> ]);
> 
> Is this an error due to the duplicate definition or will the last 'foo' win?

The last 'foo' will win, such that you can override previous definitions.

> 
> 2.
> 
> $xpath->registerPhpFunctions([]);
> 
> Is this an error or a noop?
> 

This is a no-op, just like it is the case in current PHP versions.

> 3.
> 
> Would it make sense to deprecate passing a string as "Future Scope"? Simplifying the method signature would also allow to simplify the documentation in the long run and registering a string is trivially fixed by adding square brackets.

Maybe, although I personally don't hate it that much.

> 
> In fact looking at the existing documentation at https://www.php.net/manual/en/domxpath.registerphpfunctions.php, what's the difference between 'php:function()' and 'php:functionString()'?

The difference is in the returned result.
php:functionString() will case the result to a string automatically for you, while php:function() just returns the result as-is.

> 
> Best regards
> Tim Düsterhus

Kind regards
Niels

---

## #121923 — Niels Dossche — 2023-12-04T22:11:22+00:00

URL: https://externals.io/message/121611#121923 · In reply to: #121611

Hi internals


> Hi internals
> 
> I'm opening the discussion for my RFC "Improve callbacks in ext/dom and ext/xsl".
> RFC link: https://wiki.php.net/rfc/improve_callbacks_dom_and_xsl
> 
> Kind regards
> Niels

I have extended the RFC. The new version of the document is 0.2.0.
Now not only do I propose to extend the existing registerPhpFunctions method, I also propose to add a registerPhpFunctionsNS method.
The latter would allow for a nicer syntax and a namespace-aware API that can help to avoid name clashes with many callbacks.

This means there are now two primary votes.

Kind regards
Niels

---

## #121937 — Niels Dossche — 2023-12-06T20:01:55+00:00

URL: https://externals.io/message/121611#121937 · In reply to: #121923

Hi again


> Hi internals
> 
> 
> > […]
> 
> I have extended the RFC. The new version of the document is 0.2.0.
> Now not only do I propose to extend the existing registerPhpFunctions method, I also propose to add a registerPhpFunctionsNS method.
> The latter would allow for a nicer syntax and a namespace-aware API that can help to avoid name clashes with many callbacks.
> 
> This means there are now two primary votes.
> 
> Kind regards
> Niels

I've updated my RFC again based on some feedback I got privately.
The new document version is 0.3.0.
The change is that instead of registerPhpFunctionsNS I now have registerPhpFunctionNS that no longer uses an array argument, but has a signature of
	function registerPhpFunctionNS(string $namespaceURI, string $name, callable $callable): void;
You can consult the diff on the wiki to get up to speed quickly.

Cheers
Niels

---

## #122017 — Niels Dossche — 2023-12-19T15:45:10+00:00

URL: https://externals.io/message/121611#122017 · In reply to: #121611

Hi internals


> Hi internals
> 
> I'm opening the discussion for my RFC "Improve callbacks in ext/dom and ext/xsl".
> RFC link: https://wiki.php.net/rfc/improve_callbacks_dom_and_xsl
> 
> Kind regards
> Niels

It's been almost 2 weeks since the last change to the RFC, and over a month since the discussion started.
No discussion has happened in the last 2 weeks.
I'd like to move this to voting on Thursday. Due to the holidays I will let the voting run for 3 weeks instead of 2.

Please raise any final remarks or complaints now.

Kind regards
Niels
