[php-src] master: ext/standard/head.c: no need to rely on ZEND_NUM_ARGS()

Gina Peter Banyard <[email protected]>
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Gina Peter Banyard (Girgias)
Date: 2026-07-08T17:45:22+01:00

Commit: https://github.com/php/php-src/commit/66966e625e0928633572236b2afd811bfeb66fe6
Raw diff: https://github.com/php/php-src/commit/66966e625e0928633572236b2afd811bfeb66fe6.diff

ext/standard/head.c: no need to rely on ZEND_NUM_ARGS()

Changed paths:
  M  Zend/tests/weakrefs/gh17442_1.phpt
  M  ext/standard/head.c


Diff:

diff --git a/Zend/tests/weakrefs/gh17442_1.phpt b/Zend/tests/weakrefs/gh17442_1.phpt
index fc7f60174ed9..d535c307e3be 100644
--- a/Zend/tests/weakrefs/gh17442_1.phpt
+++ b/Zend/tests/weakrefs/gh17442_1.phpt
@@ -17,6 +17,6 @@ headers_sent($obj,$generator);
 Fatal error: Uncaught Exception: Test in %s:%d
 Stack trace:
 #0 [internal function]: class@anonymous->__destruct()
-#1 %s(%d): headers_sent(NULL, 0)
+#1 %s(%d): headers_sent(NULL, NULL)
 #2 {main}
   thrown in %s on line %d
diff --git a/ext/standard/head.c b/ext/standard/head.c
index 773b6919b780..34a22327b5e7 100644
--- a/ext/standard/head.c
+++ b/ext/standard/head.c
@@ -314,14 +314,15 @@ PHP_FUNCTION(setrawcookie)
 /* {{{ Returns true if headers have already been sent, false otherwise */
 PHP_FUNCTION(headers_sent)
 {
-	zval *arg1 = NULL, *arg2 = NULL;
-	const char *file="";
-	int line=0;
+	zval *by_ref_filename = NULL;
+	zval *by_ref_line = NULL;
+	const char *file = "";
+	int line = 0;
 
 	ZEND_PARSE_PARAMETERS_START(0, 2)
 		Z_PARAM_OPTIONAL
-		Z_PARAM_ZVAL(arg1)
-		Z_PARAM_ZVAL(arg2)
+		Z_PARAM_ZVAL(by_ref_filename)
+		Z_PARAM_ZVAL(by_ref_line)
 	ZEND_PARSE_PARAMETERS_END();
 
 	if (SG(headers_sent)) {
@@ -329,17 +330,15 @@ PHP_FUNCTION(headers_sent)
 		file = php_output_get_start_filename();
 	}
 
-	switch(ZEND_NUM_ARGS()) {
-	case 2:
-		ZEND_TRY_ASSIGN_REF_LONG(arg2, line);
-		ZEND_FALLTHROUGH;
-	case 1:
+	if (by_ref_filename) {
 		if (file) {
-			ZEND_TRY_ASSIGN_REF_STRING(arg1, file);
+			ZEND_TRY_ASSIGN_REF_STRING(by_ref_filename, file);
 		} else {
-			ZEND_TRY_ASSIGN_REF_EMPTY_STRING(arg1);
+			ZEND_TRY_ASSIGN_REF_EMPTY_STRING(by_ref_filename);
 		}
-		break;
+	}
+	if (by_ref_line) {
+		ZEND_TRY_ASSIGN_REF_LONG(by_ref_line, line);
 	}
 
 	RETURN_BOOL(SG(headers_sent));
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.