Skip to content

Commit 6dec6a6

Browse files
committed
Add PHP_BUILD_DATE constant
This information can be occasionally useful, and would otherwise need to be parsed from `phpinfo()` output. However, maybe more importantly we unify the build date between what is given by `php -v` and `php -i`, since these compilation units are not necessarily preprocessed within the same second. Closes GH-16747.
1 parent 03cbb3e commit 6dec6a6

File tree

8 files changed

+28
-4
lines changed

8 files changed

+28
-4
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ PHP NEWS
88
- Core:
99
. Fixed bug GH-16665 (\array and \callable should not be usable in
1010
class_alias). (nielsdos)
11+
. Added PHP_BUILD_DATE constant. (cmb)
1112

1213
- Curl:
1314
. Added curl_multi_get_handles(). (timwolla)

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ PHP 8.5 UPGRADE NOTES
129129
10. New Global Constants
130130
========================================
131131

132+
- Core:
133+
. PHP_BUILD_DATE.
134+
132135
- POSIX:
133136
. POSIX_SC_OPEN_MAX.
134137

ext/standard/info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ PHPAPI ZEND_COLD void php_print_info(int flag)
801801
php_info_print_box_end();
802802
php_info_print_table_start();
803803
php_info_print_table_row(2, "System", ZSTR_VAL(php_uname));
804-
php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__);
804+
php_info_print_table_row(2, "Build Date", php_build_date);
805805
#ifdef PHP_BUILD_SYSTEM
806806
php_info_print_table_row(2, "Build System", PHP_BUILD_SYSTEM);
807807
#endif

main/main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ PHPAPI size_t core_globals_offset;
9797

9898
#define SAFE_FILENAME(f) ((f)?(f):"-")
9999

100+
const char php_build_date[] = __DATE__ " " __TIME__;
101+
100102
PHPAPI const char *php_version(void)
101103
{
102104
return PHP_VERSION;
@@ -110,8 +112,8 @@ PHPAPI unsigned int php_version_id(void)
110112
PHPAPI char *php_get_version(sapi_module_struct *sapi_module)
111113
{
112114
char *version_info;
113-
spprintf(&version_info, 0, "PHP %s (%s) (built: %s %s) (%s)\nCopyright (c) The PHP Group\n%s%s",
114-
PHP_VERSION, sapi_module->name, __DATE__, __TIME__,
115+
spprintf(&version_info, 0, "PHP %s (%s) (built: %s) (%s)\nCopyright (c) The PHP Group\n%s%s",
116+
PHP_VERSION, sapi_module->name, php_build_date,
115117
#ifdef ZTS
116118
"ZTS"
117119
#else

main/main.stub.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
* @cvalue PHP_VERSION_ID
3535
*/
3636
const PHP_VERSION_ID = UNKNOWN;
37+
38+
/**
39+
* @var string
40+
* @cvalue php_build_date
41+
*/
42+
const PHP_BUILD_DATE = UNKNOWN;
43+
3744
/**
3845
* @var bool
3946
* @cvalue PHP_ZTS

main/main_arginfo.h

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main/php.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ END_EXTERN_C()
265265
extern char **environ;
266266
#endif /* ifndef PHP_WIN32 */
267267

268+
extern const char php_build_date[];
269+
268270
#ifdef PHP_PWRITE_64
269271
ssize_t pwrite(int, void *, size_t, off64_t);
270272
#endif

tests/basic/build_date.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
PHP_BUILD_DATE
3+
--FILE--
4+
<?php
5+
var_dump(PHP_BUILD_DATE);
6+
?>
7+
--EXPECTREGEX--
8+
string\(20\) "[A-Za-z]{3} \d{2} \d{4} \d{2}:\d{2}:\d{2}"

0 commit comments

Comments
 (0)