2

I'm working in a C codebase for a PHP extension. This extension defines several php.ini settings. From what I've seen, there are two macros that do this. They are PHP_INI_ENTRY_EX and STD_PHP_INI_ENTRY_EX.

PHP_INI_BEGIN()
    PHP_INI_ENTRY_EX (...)
    STD_PHP_INI_ENTRY_EX (...)
PHP_INI_END()

What's the practical difference between creating a php.ini setting with one macro vs. the other? That is, I can follow the white rabbit down the macro hole and see the final C that's generated, but what I want to know is what sort behavior/functionality differences a PHP developer using these ini settings will see.

Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • 2
    Not sure if this helps, but I think the two used are `STD_PHP_INI_ENTRY` and `PHP_INI_ENTRY` https://docstore.mik.ua/orelly/webprog/php/ch14_12.htm – AbraCadaver Feb 13 '18 at 18:26
  • Thank you @AbraCadaver -- that doesn't directly answer my question, but there's lots of good/useful information at that link! – Alana Storm Feb 13 '18 at 19:15

1 Answers1

1

(the following is my best guess on how all this works -- corrections welcomed in the comments)

The STD_PHP_INI_ENTRY and STD_PHP_INI_ENTRY_EX macros allow an end-user-programmer to create ini settings whose values are saved in memory (and, presumably, can be set and fetched via ini_set/ini_get). The PHP_INI_ENTRY and PHP_INI_ENTRY_EX macros allow an end-user-programmer to create ini settings that trigger a callback function once, and then take some action in their own program/extension (i.e. setting some global-ish state in their program not related to PHP's ini system).

The _EX version of the macros take an extra parameter -- this extra parameter is a callback that PHP will use to display the ini value in places like phpinfo. For example, you cam see the ldap.maxlinks ini definition here with a display_link_numbers callback. The source then defines the display_link_numbers callback here.

The STD_ macros are designed to work with a specific sort of state object/structs. Using the above ldap.maxlinks example again, the three key parameters are max_links, zend_ldap_globals, and ldap_globals.

STD_PHP_INI_ENTRY_EX("ldap.max_links", "-1", PHP_INI_SYSTEM, OnUpdateLong,
    max_links, zend_ldap_globals, ldap_globals,
display_link_numbers)

Above, the zend_ldap_globals parameters is the name of a struct definition, setup with the the ZEND_BEGIN_MODULE_GLOBALS and ZEND_END_MODULE_GLOBALS macros. You can see the macro calls that create the zend_ldap_globals definition here. The above max_links parameter is a field on this same struct.

Finally, the ldap_globals parameter is an instance of that struct, created via the PHP_GINIT_FUNCTION macro. This macro allows a programmer to setup a "per-php-request" global and (I think) is the memory where PHP will store the ini's value. You can see the ldap per-request global setup here.

When you've setup a struct to hold you ini's state like the above, you can then use a set of predefined PHP callbacks (OnUpdateLong above) to have these values automatically set when the PHP user sets a value via php.ini (or one of the various other places a PHP ini value can be set, depending on which PHP_INI constant you've passed to your STD_ macro (PHP_INI_SYSTEM above)).

Alana Storm
  • 164,128
  • 91
  • 395
  • 599