PHP RFC: Allow loading extensions by name
This RFC proposes a unified way to configure the list of PHP extensions to load.
Today, 'extension=' and 'zend_extension=' lines in php.ini must contain the extension's file name. Unfortunately, the filename depends on the platform PHP is running on :
- On Unix-like environments, the file name has the form '<extension-name>.<suffix>'. <suffix> is 'so' on every system, except HP-UX, where it is 'sl'.
- On Windows, the file name has the form 'php_<extension-name>.dll'.
While seasoned PHP administrators are used to this mechanism, this is a real issue for newcomers.
Under Unix/Linux, the typical mistake is to uncomment an 'extension=php_xxx.dll' line in the php.ini file.
On Windows, the situation for newcomers is still more confusing, as the distributed 'php.ini' files wrongly state that the Windows syntax is 'extension=modulename.extension', giving the wrong example of 'extension=mysqli.dll'. Ten lines below, the '.ini' file contains the right ';extension=php_mysql.dll' syntax but these conflicting directives are very confusing.
The issue may also appear when writing documentation and platform-agnostic scripts.
To summarize, I think that a unified syntax to enable extensions on every environment would make the life easier for a lot of people, especially those coming to PHP.
The issue is quite easy to solve because the logic to compute the file name from an extension name is well-known.
This RFC proposes an extension to the mechanism used to load PHP and Zend extensions. In addition to file names, it adds support for bare extension name. Note that the current syntax, using file names, remains supported as before.
'extension=bz2', for example, will cause PHP to load a file named 'php_bz2.dll' on Windows, a file named 'bz2.so' on Linux, and a file named 'bz2.sl' on HP-UX.
Example php.ini files are modified because loading extensions by name becomes the recommended way of configuring additional extensions to load. File names remain supported as legacy.
Cases where the extension name is accepted :
- 'extension=' INI setting
- 'zend_extension=' INI setting
- as argument to the dl() function
Cases where the extension name cannot be used :
- The '-z' CLI option still requires an absolute file path.
- When specifying an absolute path, a filename must be provided. A line mixing a specific directory with an extension name, like 'extension=/path/to/extensions/bz2', is invalid.
Backward Incompatible Changes
None, as file names remain supported.
Proposed PHP Version(s)
To Existing Extensions
This RFC does not pretend solving every difference that may exist between Windows and Unix '.ini' configuration files.
Unaffected PHP Functionality
The '-z' CLI option does not support extension names.
Proposed Voting Choices
This RFC requires a 50%+1 majority.
Vote is now closed. RFC is approved for inclusion in 7.2.
Patches and Tests
Pull request (final) : https://github.com/php/php-src/pull/1741
After the project is implemented, this section should contain
- the version(s) it was merged to
- a link to the git commit(s)
- a link to the PHP manual entry for the feature
Keep this updated with features that were discussed on the mail lists.