Skip to content

cli: Automatically execute Closures returned from primary script - #23658

Open
TimWolla wants to merge 1 commit into
php:masterfrom
TimWolla:main-closure
Open

cli: Automatically execute Closures returned from primary script#23658
TimWolla wants to merge 1 commit into
php:masterfrom
TimWolla:main-closure

Conversation

@TimWolla

@TimWolla TimWolla commented Sep 11, 2026

Copy link
Copy Markdown
Member

Does this require an RFC?

@Girgias Girgias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this needs an RFC, but we may want to punt this to PHP next?

Comment thread sapi/cli/php_cli.c
@TimWolla

Copy link
Copy Markdown
Member Author

but we may want to punt this to PHP next?

I'm okay with that. Given that Beta 3 is already out and the next version is RC 1 this would be super late otherwise.

@TimWolla

Copy link
Copy Markdown
Member Author

A possible alternative to this might be doing something similar to Python: Defining a __MAIN__ constant with the __FILE__ of the first script. This might also allow frameworks and applications to replace their existing “was I loaded from the main entrypoint” checks (such as phpBB’s IN_PHPBB constant):

if (__MAIN__ === __FILE__) {
    main();
}

@Girgias Girgias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Implementation looks good to me. I guess some of the other details might need some discussion on the mailing list.

Comment thread sapi/cli/php_cli.c
} else {
php_execute_script(&file_handle);
zval retval;
ZVAL_UNDEF(&retval);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does php_execute_script_ex not set this to UNDEF?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't trust passing values to zval_ptr_dtor() unless I initialize them myself.

@TimWolla

Copy link
Copy Markdown
Member Author

I guess some of the other details might need some discussion on the mailing list.

Fair enough, I'll start a thread after the hard freeze.

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