Files
php-src/ext/reflection/tests/ReflectionConstant_getFileName.phpt
Daniel Scherzer f5e743a520 Add ReflectionConstant::getFileName()
Allow determining the name of the file that defined a constant, when the
constant was defined in userland code via const or define(). For constants
defined by PHP core or extensions, false is returned, matching the existing
getFileName() methods on other reflection classes.

Fixes GH-15723
Closes GH-15847
2024-10-31 16:47:45 +01:00

45 lines
1.0 KiB
PHP

--TEST--
ReflectionConstant::getFileName()
--FILE--
<?php
include "included5.inc";
function testConstant(string $name): void {
$ref = new ReflectionConstant($name);
echo "$name: ";
var_dump($ref->getFileName());
}
define('IN_CURRENT_FILE_DEFINED', 42);
const IN_CURRENT_FILE_AST = 123;
echo "From PHP:\n";
testConstant('PHP_VERSION');
testConstant('STDIN');
testConstant('STDOUT');
testConstant('STDERR');
echo "\nFrom the current file:\n";
testConstant('IN_CURRENT_FILE_DEFINED');
testConstant('IN_CURRENT_FILE_AST');
echo "\nFrom an included file:\n";
testConstant('INCLUDED_CONSTANT_DEFINED');
testConstant('INCLUDED_CONSTANT_AST');
?>
--EXPECTF--
From PHP:
PHP_VERSION: bool(false)
STDIN: bool(false)
STDOUT: bool(false)
STDERR: bool(false)
From the current file:
IN_CURRENT_FILE_DEFINED: string(%d) "%sReflectionConstant_getFileName.php"
IN_CURRENT_FILE_AST: string(%d) "%sReflectionConstant_getFileName.php"
From an included file:
INCLUDED_CONSTANT_DEFINED: string(%d) "%sincluded5.inc"
INCLUDED_CONSTANT_AST: string(%d) "%sincluded5.inc"