diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index 13b5e6a394434..eb5ccd7bd0bd0 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -23,6 +23,8 @@ PHP 8.5 INTERNALS UPGRADE NOTES for fake closures. . Added smart_string_append_printf() matching smart_str_append_printf() for char* instead of zend_string*-based smart strings. + . Added php_build_provider() to retrieve the value of PHP_BUILD_PROVIDER at + runtime. ======================== 2. Build system changes diff --git a/ext/standard/info.c b/ext/standard/info.c index 0211265f954a9..952f0f92fe6e2 100644 --- a/ext/standard/info.c +++ b/ext/standard/info.c @@ -805,9 +805,9 @@ PHPAPI ZEND_COLD void php_print_info(int flag) #ifdef PHP_BUILD_SYSTEM php_info_print_table_row(2, "Build System", PHP_BUILD_SYSTEM); #endif -#ifdef PHP_BUILD_PROVIDER - php_info_print_table_row(2, "Build Provider", PHP_BUILD_PROVIDER); -#endif + if (php_build_provider()) { + php_info_print_table_row(2, "Build Provider", php_build_provider()); + } #ifdef PHP_BUILD_COMPILER php_info_print_table_row(2, "Compiler", PHP_BUILD_COMPILER); #endif diff --git a/main/main.c b/main/main.c index 415cb02185e94..50894939782a0 100644 --- a/main/main.c +++ b/main/main.c @@ -74,6 +74,7 @@ #include "zend_dtrace.h" #include "zend_observer.h" #include "zend_system_id.h" +#include "zend_smart_string.h" #include "php_content_types.h" #include "php_ticks.h" @@ -99,20 +100,30 @@ PHPAPI size_t core_globals_offset; const char php_build_date[] = __DATE__ " " __TIME__; -PHPAPI const char *php_version(void) +ZEND_ATTRIBUTE_CONST PHPAPI const char *php_version(void) { return PHP_VERSION; } -PHPAPI unsigned int php_version_id(void) +ZEND_ATTRIBUTE_CONST PHPAPI unsigned int php_version_id(void) { return PHP_VERSION_ID; } +ZEND_ATTRIBUTE_CONST PHPAPI const char *php_build_provider(void) +{ +#ifdef PHP_BUILD_PROVIDER + return PHP_BUILD_PROVIDER; +#else + return NULL; +#endif +} + PHPAPI char *php_get_version(sapi_module_struct *sapi_module) { - char *version_info; - spprintf(&version_info, 0, "PHP %s (%s) (built: %s) (%s)\nCopyright (c) The PHP Group\n%s%s", + smart_string version_info = {0}; + smart_string_append_printf(&version_info, + "PHP %s (%s) (built: %s) (%s)\n", PHP_VERSION, sapi_module->name, php_build_date, #ifdef ZTS "ZTS" @@ -131,16 +142,15 @@ PHPAPI char *php_get_version(sapi_module_struct *sapi_module) #ifdef HAVE_GCOV " GCOV" #endif - , -#ifdef PHP_BUILD_PROVIDER - "Built by " PHP_BUILD_PROVIDER "\n" -#else - "" -#endif - , - get_zend_version() ); - return version_info; + smart_string_appends(&version_info, "Copyright (c) The PHP Group\n"); + if (php_build_provider()) { + smart_string_append_printf(&version_info, "Built by %s\n", php_build_provider()); + } + smart_string_appends(&version_info, get_zend_version()); + smart_string_0(&version_info); + + return version_info.c; } PHPAPI void php_print_version(sapi_module_struct *sapi_module) diff --git a/main/php_main.h b/main/php_main.h index 889fcf48501f0..a5b049487db23 100644 --- a/main/php_main.h +++ b/main/php_main.h @@ -28,13 +28,20 @@ BEGIN_EXTERN_C() * extensions which want to know the version of PHP at run-time, rather than * the version they were built with at compile-time. */ -PHPAPI const char *php_version(void); +ZEND_ATTRIBUTE_CONST PHPAPI const char *php_version(void); /* Returns the PHP version id the engine was built with. This is useful for * extensions which want to know the version of PHP at run-time, rather than * the version they were built with at compile-time. */ -PHPAPI unsigned int php_version_id(void); +ZEND_ATTRIBUTE_CONST PHPAPI unsigned int php_version_id(void); + +/* Returns the build provider specified at build time. NULL is returned if + * no build provider was specified. This is useful for extensions which want + * to know the origin of a PHP binary at run-time, for example to provide + * statistics. + */ +ZEND_ATTRIBUTE_CONST PHPAPI const char *php_build_provider(void); /* Prints the PHP version string for the -v option. It's in main/ so that * it can be shared between SAPIs.