Skip to content

POC https://wiki.php.net/rfc/function-composition #18800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sgolemon
Copy link
Member

@sgolemon sgolemon commented Jun 7, 2025

No description provided.

@sgolemon
Copy link
Member Author

sgolemon commented Jun 7, 2025

Needs more testing, and as @Crell already noted on discord, there's a gap for:

class A {
    public function __invoke($x) { return $x; }
}

$cb = (new A) + (new A);

As these have no class level overloading of the add operator.

@@ -720,6 +729,7 @@ void zend_register_closure_ce(void) /* {{{ */
closure_handlers.get_debug_info = zend_closure_get_debug_info;
closure_handlers.get_closure = zend_closure_get_closure;
closure_handlers.get_gc = zend_closure_get_gc;
closure_handlers.do_operation = zend_closure_do_operation;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! That's not at all how I would have thought to do it.

If I follow, this is implemented as an operator override on closures, rather than special casing the operator itself, yes?

@Crell
Copy link
Contributor

Crell commented Jun 8, 2025

Hm, I can't even get this to compile, even with clean. Is there a file missing?

/usr/bin/ld: Zend/zend_closures.o: in function `zend_closure_do_operation':
/home/crell/Projects/Forks/php-src/Zend/zend_closures.c:714: undefined reference to `zend_composed_callable_new_from_pair'
/usr/bin/ld: Zend/zend_interfaces.o: in function `zend_register_interfaces':
/home/crell/Projects/Forks/php-src/Zend/zend_interfaces.c:681: undefined reference to `zend_register_composed_callable'
/usr/bin/ld: Zend/zend_interfaces.o:(.data.rel.ro+0x8): undefined reference to `zim_ComposedCallable___construct'
/usr/bin/ld: Zend/zend_interfaces.o:(.data.rel.ro+0x38): undefined reference to `zim_ComposedCallable___invoke'
/usr/bin/ld: Zend/zend_interfaces.o:(.data.rel.ro+0x68): undefined reference to `zim_ComposedCallable___debugInfo'
/usr/bin/ld: Zend/zend_interfaces.o:(.data.rel.ro+0x98): undefined reference to `zim_ComposedCallable_append'
/usr/bin/ld: Zend/zend_interfaces.o:(.data.rel.ro+0xc8): undefined reference to `zim_ComposedCallable_insert'
/usr/bin/ld: Zend/zend_interfaces.o:(.data.rel.ro+0xf8): undefined reference to `zim_ComposedCallable_prepend'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants