[php-src] PHP-8.4: Merge branch 'PHP-8.3' into PHP-8.4

From: Date: Mon, 12 May 2025 06:56:26 +0000
Subject: [php-src] PHP-8.4: Merge branch 'PHP-8.3' into PHP-8.4
Groups: php.cvs 
Request: Send a blank email to [email protected] to get a copy of this message
Author: Tim Düsterhus (TimWolla)
Date: 2025-05-12T08:45:26+02:00

Commit: https://github.com/php/php-src/commit/40edd58d36b8720bdb36495bf375fcf5b0f81c1c
Raw diff: https://github.com/php/php-src/commit/40edd58d36b8720bdb36495bf375fcf5b0f81c1c.diff

Merge branch 'PHP-8.3' into PHP-8.4

* PHP-8.3:
  standard: Take zend.assertions into account for dynamic calls to
assert() (#18521)

Changed paths:
  A  ext/standard/tests/assert/gh18509.phpt
  M  NEWS
  M  ext/standard/assert.c


Diff:

diff --git a/NEWS b/NEWS
index ebb93b6489c54..737e352b2d6e6 100644
--- a/NEWS
+++ b/NEWS
@@ -37,6 +37,8 @@ PHP                                                                        NEWS
 - Standard:
   . Fixed bug GH-17403 (Potential deadlock when putenv fails). (nielsdos)
   . Fixed bug GH-18400 (http_build_query type error is inaccurate). (nielsdos)
+  . Fixed bug GH-18509 (Dynamic calls to assert() ignore zend.assertions).
+    (timwolla)
 
 - Windows:
   . Fix leak+crash with sapi_windows_set_ctrl_handler(). (nielsdos)
diff --git a/ext/standard/assert.c b/ext/standard/assert.c
index f0b6adadbe17d..258447576e1f4 100644
--- a/ext/standard/assert.c
+++ b/ext/standard/assert.c
@@ -178,7 +178,11 @@ PHP_FUNCTION(assert)
 	zend_string *description_str = NULL;
 	zend_object *description_obj = NULL;
 
-	if (!ASSERTG(active)) {
+	/* EG(assertions) <= 0 is only reachable by dynamic calls to assert(),
+	 * since calls known at compile time will skip the entire call when
+	 * assertions are disabled.
+	 */
+	if (!ASSERTG(active) || EG(assertions) <= 0) {
 		RETURN_TRUE;
 	}
 
diff --git a/ext/standard/tests/assert/gh18509.phpt b/ext/standard/tests/assert/gh18509.phpt
new file mode 100644
index 0000000000000..2bf1a04c87c69
--- /dev/null
+++ b/ext/standard/tests/assert/gh18509.phpt
@@ -0,0 +1,23 @@
+--TEST--
+GH-18509: Dynamic calls to assert() ignore zend.assertions
+--INI--
+zend.assertions=0
+--FILE--
+<?php
+
+$c = "assert";
+
+$c(false);
+
+var_dump(array_map(assert(...), [true, true, false]));
+
+?>
+--EXPECT--
+array(3) {
+  [0]=>
+  bool(true)
+  [1]=>
+  bool(true)
+  [2]=>
+  bool(true)
+}


Thread (1 message)

  • Tim Düsterhus
« previous php.cvs (#134115) next »