@@ -5,22 +5,40 @@ ReflectionConstant::getFileName()
5
5
6
6
include "included5.inc " ;
7
7
8
- $ reflectionConstant = new ReflectionConstant ('PHP_VERSION ' );
9
- var_dump ($ reflectionConstant ->getFileName ());
8
+ function testConstant ( string $ name ): void {
9
+ $ ref = new ReflectionConstant ( $ name );
10
+ echo "$ name: " ;
11
+ var_dump ( $ ref ->getFileName () );
12
+ }
10
13
11
- define ('IN_CURRENT_FILE ' , 42 );
12
- $ reflectionConstant = new ReflectionConstant ('IN_CURRENT_FILE ' );
13
- var_dump ($ reflectionConstant ->getFileName ());
14
+ define ('IN_CURRENT_FILE_DEFINED ' , 42 );
15
+ const IN_CURRENT_FILE_AST = 123 ;
14
16
15
- $ reflectionConstant = new ReflectionConstant ('INCLUDED_CONSTANT_DEFINED ' );
16
- var_dump ($ reflectionConstant ->getFileName ());
17
+ echo "From PHP: \n" ;
18
+ testConstant ( 'PHP_VERSION ' );
19
+ testConstant ( 'STDIN ' );
20
+ testConstant ( 'STDOUT ' );
21
+ testConstant ( 'STDERR ' );
17
22
18
- $ reflectionConstant = new ReflectionConstant ('INCLUDED_CONSTANT_AST ' );
19
- var_dump ($ reflectionConstant ->getFileName ());
23
+ echo "\nFrom the current file: \n" ;
24
+ testConstant ( 'IN_CURRENT_FILE_DEFINED ' );
25
+ testConstant ( 'IN_CURRENT_FILE_AST ' );
20
26
27
+ echo "\nFrom an included file: \n" ;
28
+ testConstant ( 'INCLUDED_CONSTANT_DEFINED ' );
29
+ testConstant ( 'INCLUDED_CONSTANT_AST ' );
21
30
?>
22
31
--EXPECTF--
23
- bool(false)
24
- string(%d) "%sReflectionConstant_getFileName.php"
25
- string(%d) "%sincluded5.inc"
26
- string(%d) "%sincluded5.inc"
32
+ From PHP:
33
+ PHP_VERSION: bool(false)
34
+ STDIN: bool(false)
35
+ STDOUT: bool(false)
36
+ STDERR: bool(false)
37
+
38
+ From the current file:
39
+ IN_CURRENT_FILE_DEFINED: string(%d) "%sReflectionConstant_getFileName.php"
40
+ IN_CURRENT_FILE_AST: string(%d) "%sReflectionConstant_getFileName.php"
41
+
42
+ From an included file:
43
+ INCLUDED_CONSTANT_DEFINED: string(%d) "%sincluded5.inc"
44
+ INCLUDED_CONSTANT_AST: string(%d) "%sincluded5.inc"
0 commit comments