File: closure_065.phpt

package info (click to toggle)
php8.4 8.4.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 211,276 kB
  • sloc: ansic: 1,176,142; php: 35,419; sh: 11,964; cpp: 7,208; pascal: 4,951; javascript: 3,091; asm: 2,817; yacc: 2,411; makefile: 696; xml: 446; python: 301; awk: 148
file content (88 lines) | stat: -rw-r--r-- 2,207 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
--TEST--
The closure name includes the source location (2)
--FILE--
<?php

namespace NameSpaceName {
    class ClassName {
        public function methodName() {
            $c = function () {};
            $r = new \ReflectionFunction($c);
            var_dump($r->name);
        }

        public function nestedClosure() {
            $c = function () {
                $c = function () {
                    $c = function () {};
                    $r = new \ReflectionFunction($c);
                    var_dump($r->name);
                };

                $c();
            };

            $c();
        }
    }

    function function_name() {
        $c = function () { };
        $r = new \ReflectionFunction($c);
        var_dump($r->name);
    }
}

namespace {
    class ClassName {
        public function methodName() {
            $c = function () {};
            $r = new \ReflectionFunction($c);
            var_dump($r->name);
        }

        public function nestedClosure() {
            $c = function () {
                $c = function () {
                    $c = function () {};
                    $r = new \ReflectionFunction($c);
                    var_dump($r->name);
                };

                $c();
            };

            $c();
        }
    }

    function function_name() {
        $c = function () { };
        $r = new \ReflectionFunction($c);
        var_dump($r->name);
    }

    $class = new \NameSpaceName\ClassName();
    $class->methodName();
    $class->nestedClosure();
    \NameSpaceName\function_name();

    $class = new \ClassName();
    $class->methodName();
    $class->nestedClosure();
    \function_name();

    $c = function () { };
    $r = new \ReflectionFunction($c);
    var_dump($r->name);
}

?>
--EXPECTF--
string(49) "{closure:NameSpaceName\ClassName::methodName():6}"
string(79) "{closure:{closure:{closure:NameSpaceName\ClassName::nestedClosure():12}:13}:14}"
string(42) "{closure:NameSpaceName\function_name():27}"
string(36) "{closure:ClassName::methodName():36}"
string(65) "{closure:{closure:{closure:ClassName::nestedClosure():42}:43}:44}"
string(28) "{closure:function_name():57}"
string(%d) "{closure:%sclosure_%d.php:72}"