[php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5
| From: | Tim Düsterhus | Date: | Thu, 19 Nov 2026 09:51:00 +0000 |
| Subject: | [php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143870@lists.php.net to get a copy of this message | ||
Author: Tim Düsterhus (TimWolla)
Date: 2026-11-19T10:50:50+01:00
Commit: https://github.com/php/php-src/commit/3b215dd88de9096a3de105d6567a9557e8310bf4
Raw diff: https://github.com/php/php-src/commit/3b215dd88de9096a3de105d6567a9557e8310bf4.diff
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
standard: Support numeric components of arbitrary length in
version_compare()
(#25536)
Changed paths:
M NEWS
M ext/standard/tests/versioning/gh25474.phpt
M ext/standard/tests/versioning/version_compare.phpt
M ext/standard/versioning.c
Diff:
diff --git a/NEWS b/NEWS
index 222fc76b3f23..ca38bc37b78a 100644
--- a/NEWS
+++ b/NEWS
@@ -147,7 +147,7 @@ PHP NEWS
- Standard:
. Fixed bug GH-25474 (version_compare() treats large numeric parts as equal
- on 64-bit Windows). (lazerg)
+ on 64-bit Windows). (lazerg, timwolla)
. Fixed bug GH-25387 (Uploaded files leak in request_parse_body()).
(Kévin Dunglas)
. Fixed bug GH-24743 (var_export() ignores exceptions from lazy object
diff --git a/ext/standard/tests/versioning/gh25474.phpt b/ext/standard/tests/versioning/gh25474.phpt
index c055b69d88bf..7bc4182973c3 100644
--- a/ext/standard/tests/versioning/gh25474.phpt
+++ b/ext/standard/tests/versioning/gh25474.phpt
@@ -2,10 +2,6 @@
GH-25474 (version_compare() treats numeric parts > 2147483647 as equal on Windows)
--CREDITS--
HFigarella
---SKIPIF--
-<?php
-if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
-?>
--FILE--
<?php
var_dump(version_compare('2147483648', '2147483647'));
diff --git a/ext/standard/tests/versioning/version_compare.phpt
b/ext/standard/tests/versioning/version_compare.phpt
index e22ddabfa56b..db7f199c18ed 100644
--- a/ext/standard/tests/versioning/version_compare.phpt
+++ b/ext/standard/tests/versioning/version_compare.phpt
@@ -24,6 +24,15 @@ foreach ($special_forms as $f1) {
}
test("1.2.", "1.2.");
test("1.2..", "1.2..");
+test("1.2147483647", "1.2147483648");
+test("1.4294967295", "1.4294967296");
+test("1.9223372036854775807", "1.9223372036854775808");
+test("1.18446744073709551615", "1.18446744073709551616");
+test("1.99999999999999999999999999", "1.99999999999999999999999999");
+test("1.99999999999999999999999999", "1.999999999999999999999999999");
+test("1.99999999999999999999999998", "1.99999999999999999999999999");
+test("1.0001", "1.001");
+test("1.0001", "1.002");
print "TESTING OPERATORS\n";
foreach ($special_forms as $f1) {
@@ -111,6 +120,15 @@ TESTING COMPARE
1.0pl1 = 1.0pl1
1.2. = 1.2.
1.2.. = 1.2..
+1.2147483647 < 1.2147483648
+1.4294967295 < 1.4294967296
+1.9223372036854775807 < 1.9223372036854775808
+1.18446744073709551615 < 1.18446744073709551616
+1.99999999999999999999999999 = 1.99999999999999999999999999
+1.99999999999999999999999999 < 1.999999999999999999999999999
+1.99999999999999999999999998 < 1.99999999999999999999999999
+1.0001 = 1.001
+1.0001 < 1.002
TESTING OPERATORS
1.0-dev lt 1.0-dev : false
1.0-dev < 1.0-dev : false
diff --git a/ext/standard/versioning.c b/ext/standard/versioning.c
index 4b3d4180096d..cf34d0d8f888 100644
--- a/ext/standard/versioning.c
+++ b/ext/standard/versioning.c
@@ -123,6 +123,26 @@ static int compare_special_version_forms(char *form1, char *form2)
}
/* }}} */
+
+static int compare_numeric_version_forms(const char *num1, const char *num2)
+{
+ while (*num1 == '0') {
+ num1++;
+ }
+ while (*num2 == '0') {
+ num2++;
+ }
+
+ size_t len1 = strspn(num1, "0123456789");
+ size_t len2 = strspn(num2, "0123456789");
+
+ if (len1 != len2) {
+ return ZEND_THREEWAY_COMPARE(len1, len2);
+ }
+
+ return ZEND_NORMALIZE_BOOL(memcmp(num1, num2, len1));
+}
+
/* {{{ php_version_compare() */
PHPAPI int
@@ -131,7 +151,6 @@ php_version_compare(const char *orig_ver1, const char *orig_ver2)
char *ver1;
char *ver2;
char *p1, *p2, *n1, *n2;
- zend_long l1, l2;
int compare = 0;
if (!*orig_ver1 || !*orig_ver2) {
@@ -162,9 +181,7 @@ php_version_compare(const char *orig_ver1, const char *orig_ver2)
}
if (isdigit((unsigned char)*p1) && isdigit((unsigned char)*p2)) {
/* compare element numerically */
- l1 = ZEND_STRTOL(p1, NULL, 10);
- l2 = ZEND_STRTOL(p2, NULL, 10);
- compare = ZEND_NORMALIZE_BOOL(l1 - l2);
+ compare = compare_numeric_version_forms(p1, p2);
} else if (!isdigit((unsigned char)*p1) && !isdigit((unsigned char)*p2)) {
/* compare element names */
compare = compare_special_version_forms(p1, p2);