Skip to content

Commit 66966e6

Browse files
committed
ext/standard/head.c: no need to rely on ZEND_NUM_ARGS()
1 parent 9b1cdc5 commit 66966e6

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

Zend/tests/weakrefs/gh17442_1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ headers_sent($obj,$generator);
1717
Fatal error: Uncaught Exception: Test in %s:%d
1818
Stack trace:
1919
#0 [internal function]: class@anonymous->__destruct()
20-
#1 %s(%d): headers_sent(NULL, 0)
20+
#1 %s(%d): headers_sent(NULL, NULL)
2121
#2 {main}
2222
thrown in %s on line %d

ext/standard/head.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -314,32 +314,31 @@ PHP_FUNCTION(setrawcookie)
314314
/* {{{ Returns true if headers have already been sent, false otherwise */
315315
PHP_FUNCTION(headers_sent)
316316
{
317-
zval *arg1 = NULL, *arg2 = NULL;
318-
const char *file="";
319-
int line=0;
317+
zval *by_ref_filename = NULL;
318+
zval *by_ref_line = NULL;
319+
const char *file = "";
320+
int line = 0;
320321

321322
ZEND_PARSE_PARAMETERS_START(0, 2)
322323
Z_PARAM_OPTIONAL
323-
Z_PARAM_ZVAL(arg1)
324-
Z_PARAM_ZVAL(arg2)
324+
Z_PARAM_ZVAL(by_ref_filename)
325+
Z_PARAM_ZVAL(by_ref_line)
325326
ZEND_PARSE_PARAMETERS_END();
326327

327328
if (SG(headers_sent)) {
328329
line = php_output_get_start_lineno();
329330
file = php_output_get_start_filename();
330331
}
331332

332-
switch(ZEND_NUM_ARGS()) {
333-
case 2:
334-
ZEND_TRY_ASSIGN_REF_LONG(arg2, line);
335-
ZEND_FALLTHROUGH;
336-
case 1:
333+
if (by_ref_filename) {
337334
if (file) {
338-
ZEND_TRY_ASSIGN_REF_STRING(arg1, file);
335+
ZEND_TRY_ASSIGN_REF_STRING(by_ref_filename, file);
339336
} else {
340-
ZEND_TRY_ASSIGN_REF_EMPTY_STRING(arg1);
337+
ZEND_TRY_ASSIGN_REF_EMPTY_STRING(by_ref_filename);
341338
}
342-
break;
339+
}
340+
if (by_ref_line) {
341+
ZEND_TRY_ASSIGN_REF_LONG(by_ref_line, line);
343342
}
344343

345344
RETURN_BOOL(SG(headers_sent));

0 commit comments

Comments
 (0)