xref: /PHP-7.4/Zend/tests/traits/bug55214.phpt (revision 782352c5)
1--TEST--
2Bug #55214 (Use of __CLASS__ within trait returns trait name not class name)
3--FILE--
4<?php
5
6trait ATrait {
7  public static $static_var = __CLASS__;
8  public $var = __CLASS__;
9
10  public static function get_class_name() {
11    return __CLASS__;
12  }
13
14  public function get_class_name_obj() {
15    return __CLASS__;
16  }
17
18  public static function get_class_name2() {
19    return self::$static_var;
20  }
21
22  public function get_class_name_obj2() {
23    return $this->var;
24  }
25}
26
27trait Indirect {
28	use ATrait;
29}
30
31class SomeClass {
32   use ATrait;
33}
34
35class UsingIndirect {
36	use Indirect;
37}
38
39$r = SomeClass::get_class_name();
40var_dump($r);
41$r = SomeClass::get_class_name2();
42var_dump($r);
43
44$o = new SomeClass();
45$r = $o->get_class_name_obj();
46var_dump($r);
47$r = $o->get_class_name_obj2();
48var_dump($r);
49
50$r = UsingIndirect::get_class_name();
51var_dump($r);
52$r = UsingIndirect::get_class_name2();
53var_dump($r);
54
55$o = new UsingIndirect();
56$r = $o->get_class_name_obj();
57var_dump($r);
58$r = $o->get_class_name_obj2();
59var_dump($r);
60
61
62?>
63--EXPECT--
64string(9) "SomeClass"
65string(9) "SomeClass"
66string(9) "SomeClass"
67string(9) "SomeClass"
68string(13) "UsingIndirect"
69string(13) "UsingIndirect"
70string(13) "UsingIndirect"
71string(13) "UsingIndirect"
72