It should be possible to ship PHP Extensions that contain both C and PHP code to achieve their goal. While C code is obviously much faster, for many extensions it is viable to build glue code, useful wrappers and performance uncritical code using PHP.
The auto_prepend mechanism is improved to contain a list of files to pass to zend_execute_scripts instead of just using the INI value for auto_prepend.
If a php.ini value for auto_prepend is configured it will be loaded after all the PHP files registered by extensions.
This functionality can be achieved already using RINIT to emulate this sort of behavior. The following three extensions use this sort of behavior:
Others have expressed their wish to use this feature.
Using RINIT is error prone and a little bit dangerous, because is a bit too early for some data to be cleanly created (globals).
Adding this kind of API in a straightforward way would allow extension authors to make use of PHP for parts of their project. This simplifies installation for users.
The exact changes are up for discussion, this is how I propose it might work:
The API of zend_execute_scripts needs to change for this:
-ZEND_API int zend_execute_scripts(int type, zval *retval, int file_count, ...); +ZEND_API int zend_execute_scripts(int type, zval *retval, zend_file_handle **files);
We can introduce a new function zend_execute_script that can be used by code that called zend_execute_scripts before:
ZEND_API int zend_execute_script(int type, zval *retval, zend_file_handle *file);
Then php_execute_scripts can build the list of files from extension prepends, ini prepend, primary file and append files.
Nothing
PHP7
SAPIs must not be updated *unless* they use zend_execute_scripts directly.
No
Not verified, but given the locality of the change in php_execute_scripts and reusing of an exisitig feature, it does not seem likely to break.
This will be a yes/no vote with 50%+1 majority, because it is not a public API to change only introducing a new one in the Engine Core.
Working on a prototype.
v0.1.1: Fix typo in code example.