blob: 72a460abaae0f25f2a1568c467efd606d6f1861c (
plain)
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
|
--TEST--
class name as scalar from ::class keyword
--FILE--
<?php
namespace Foo\Bar {
class One {
// compile time constants
const A = self::class;
const B = Two::class;
}
class Two extends One {
public static function run() {
var_dump(self::class); // self compile time lookup
var_dump(static::class); // runtime lookup
var_dump(parent::class); // runtime lookup
var_dump(Baz::class); // default compile time lookup
}
}
class Three extends Two {
// compile time static lookups
public static function checkCompileTime(
$one = self::class,
$two = Baz::class,
$three = One::A,
$four = self::B
) {
var_dump($one, $two, $three, $four);
}
}
echo "In NS\n";
var_dump(Moo::CLASS); // resolve in namespace
}
namespace {
use Bee\Bop as Moo,
Foo\Bar\One;
echo "Top\n";
var_dump(One::class); // resolve from use
var_dump(Boo::class); // resolve in global namespace
var_dump(Moo::CLASS); // resolve from use as
var_dump(\Moo::Class); // resolve fully qualified
$class = One::class; // assign class as scalar to var
$x = new $class; // create new class from original scalar assignment
var_dump($x);
Foo\Bar\Two::run(); // resolve runtime lookups
echo "Parent\n";
Foo\Bar\Three::run(); // resolve runtime lookups with inheritance
echo "Compile Check\n";
Foo\Bar\Three::checkCompileTime();
}
?>
--EXPECT--
In NS
string(11) "Foo\Bar\Moo"
Top
string(11) "Foo\Bar\One"
string(3) "Boo"
string(7) "Bee\Bop"
string(3) "Moo"
object(Foo\Bar\One)#1 (0) {
}
string(11) "Foo\Bar\Two"
string(11) "Foo\Bar\Two"
string(11) "Foo\Bar\One"
string(11) "Foo\Bar\Baz"
Parent
string(11) "Foo\Bar\Two"
string(13) "Foo\Bar\Three"
string(11) "Foo\Bar\One"
string(11) "Foo\Bar\Baz"
Compile Check
string(13) "Foo\Bar\Three"
string(11) "Foo\Bar\Baz"
string(11) "Foo\Bar\One"
string(11) "Foo\Bar\Two"
|