Skip to content

Commit 452c5ac

Browse files
authored
Fix incorrect filename of dl()'d internal consts (#16721)
We should only attempt to fetch the current filename for user constants. dl() may attempt to register internal constants after execution has already started, thus incorrectly linking the user file invoking dl(). See GH-16663
1 parent 5c76ef7 commit 452c5ac

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

Zend/zend_constants.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,12 @@ ZEND_API zend_result zend_register_constant(zend_constant *c)
504504
name = c->name;
505505
}
506506

507-
zend_string *filename = zend_get_executed_filename_ex();
508-
if (filename == NULL) {
509-
c->filename = NULL;
510-
} else {
511-
c->filename = zend_string_copy(filename);
507+
c->filename = NULL;
508+
if (ZEND_CONSTANT_MODULE_NUMBER(c) == PHP_USER_CONSTANT) {
509+
zend_string *filename = zend_get_executed_filename_ex();
510+
if (filename) {
511+
c->filename = zend_string_copy(filename);
512+
}
512513
}
513514

514515
/* Check if the user is trying to define any special constant */

ext/dl_test/dl_test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ PHP_MINIT_FUNCTION(dl_test)
9494
fprintf(stderr, "DL TEST MINIT\n");
9595
}
9696

97+
register_dl_test_symbols(module_number);
98+
9799
return SUCCESS;
98100
}
99101
/* }}} */

ext/dl_test/dl_test.stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88
function dl_test_test1(): void {}
99

1010
function dl_test_test2(string $str = ""): string {}
11+
12+
/** @var int */
13+
const DL_TEST_CONST = 42;

ext/dl_test/dl_test_arginfo.h

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)