xref: /PHP-7.1/Zend/tests/closure_bug66622.phpt (revision 113213f0)
1--TEST--
2Bug 66622: Closures do not correctly capture the late bound class (static::) in some cases
3--FILE--
4<?php
5class A {
6    static function name() { return 'A'; }
7    function foo() {
8        $fn = function() { return static::name(); };
9        echo static::name() . ' vs ' . $fn() . "\n";
10    }
11    function bar() {
12        $fn = static function() { return static::name(); };
13        echo static::name() . ' vs ' . $fn() . "\n";
14    }
15    static function baz() {
16        $fn = function() { return static::name(); };
17        echo static::name() . ' vs ' . $fn() . "\n";
18    }
19}
20class B extends A {
21    static function name() { return 'B'; }
22}
23
24function test() {
25    (new B)->foo();
26    (new B)->bar();
27    (new B)->baz();
28    B::baz();
29}
30test();
31--EXPECT--
32B vs B
33B vs B
34B vs B
35B vs B
36