[php-src] master: Merge branch 'PHP-8.4'

From: Date: Mon, 12 May 2025 06:56:38 +0000
Subject: [php-src] master: Merge branch '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:37+02:00

Commit: https://github.com/php/php-src/commit/5626e65af259be839fc39f8a69009669110a0c35
Raw diff: https://github.com/php/php-src/commit/5626e65af259be839fc39f8a69009669110a0c35.diff

Merge branch 'PHP-8.4'

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

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


Diff:

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 (#134116) next »