Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle constants declared with const
  • Loading branch information
DanielEScherzer committed Oct 25, 2024
commit 2fa74873b47781abfb22c25ec2a37219b7ea7918
7 changes: 7 additions & 0 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -8232,6 +8232,13 @@ ZEND_VM_HANDLER(143, ZEND_DECLARE_CONST, CONST, CONST)
ZEND_CONSTANT_SET_FLAGS(&c, 0, PHP_USER_CONSTANT);
c.name = zend_string_copy(Z_STR_P(name));

zend_string *filename = zend_get_executed_filename_ex();
if (filename == NULL) {
c.filename = NULL;
} else {
c.filename = zend_string_copy(filename);
}

if (zend_register_constant(&c) == FAILURE) {
}

Expand Down
7 changes: 7 additions & 0 deletions Zend/zend_vm_execute.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion ext/reflection/tests/ReflectionConstant_getFileName.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ define('IN_CURRENT_FILE', 42);
$reflectionConstant = new ReflectionConstant('IN_CURRENT_FILE');
var_dump($reflectionConstant->getFileName());

$reflectionConstant = new ReflectionConstant('INCLUDED_CONSTANT');
$reflectionConstant = new ReflectionConstant('INCLUDED_CONSTANT_DEFINED');
var_dump($reflectionConstant->getFileName());

$reflectionConstant = new ReflectionConstant('INCLUDED_CONSTANT_AST');
var_dump($reflectionConstant->getFileName());

?>
--EXPECTF--
bool(false)
string(%d) "%sReflectionConstant_getFileName.php"
string(%d) "%sincluded5.inc"
string(%d) "%sincluded5.inc"
4 changes: 3 additions & 1 deletion ext/reflection/tests/included5.inc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php
define('INCLUDED_CONSTANT', 'Foo');
define('INCLUDED_CONSTANT_DEFINED', 'Foo');

const INCLUDED_CONSTANT_AST = 'Bar';
?>