• Increase font size
  • Default font size
  • Decrease font size
Home Ideas Loading PHP extensions by name

Loading PHP extensions by name

E-mail Print
Read : 21,306 times
(0 votes, average 0 out of 5)



!!! Feature implemented in PHP 7.2.0 !!!

Today, PHP extensions are loaded using their file names. Unfortunately, this filename depends on the operating system. So, when they want to activate an extension, newcomers are confused about the exact directive they must add to the php.ini file. The php.ini comments are also very confusing, using the word 'extension' as a synonym for 'file suffix' and providing examples using the windows syntax only.

Fortunately, the rule to derive the file name from the extension name is known and simple :

  • On Windows, the file name is :

{ppc:code}php_<extension-name>.dll{/}

  • On other environments, the filename is :

{ppc:code}<extension-name>.<PHP_SHLIB_SUFFIX>{/}

where <PHP_SHLIB_SUFFIX> is a constant provided by the PHP core.

So, we have everything we need to allow users load their extensions using the extension name only, making it much easier for newcomers and non-specialists.

I propose to keep the same syntax :

{ppc:code}extension=<string>{/}

For backwards compatibility, the logic will be :

  • First, consider <string> as a filename, and search if a file by this name exists. If it is found, use this file.
  • Then, if <string> does not contain any '/' or '\' character, consider it as an extension name, compute the corresponding filename using the rules listed above, and load this file.

This change will also apply to Zend extensions ('zend_extension=' directive) and to the dl() function.

 

Please login or register to add a comment