Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add php_build_provider() #18168

Merged
merged 4 commits into from
Mar 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions ext/standard/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 23 additions & 13 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions main/php_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down