3 // This error handler swallows typehint errors, which is
4 // disallowed in RepoAuthoritative mode. Thus, this test
5 // is set to be norepo.
6 function err($code, $msg) {
7 echo "Handled ${code}: $msg", "\n";
10 set_error_handler('err');
12 class CExplicit
implements Stringish
{
13 public function __toString() {
19 public function __toString() {
25 public function __toString() { return __TRAIT__
; }
28 interface IStringish
{
29 public function __toString();
36 function f1(?Stringish
$x): void
{
37 $s = Stringish
::class;
38 echo ($x instanceof Stringish
) ?
"true" : "false", ", ";
39 echo ($x instanceof $s) ?
"true" : "false", ", ";
44 function f2(Stringish
$x): void
{
45 $s = Stringish
::class;
46 echo ($x instanceof Stringish
) ?
"true" : "false", ", ";
47 echo ($x instanceof $s) ?
"true" : "false", ", ";
52 function test_functionality() {
53 echo '********** static string **********', "\n";
54 f1("a boring string");
55 f2("a boring string");
57 echo '********** dynamic string **********', "\n";
65 echo '********** explicit implements **********', "\n";
66 $explicit = new CExplicit();
70 echo '********** implicit implements **********', "\n";
71 $implicit = new CImplicit();
75 echo '********** via trait implements **********', "\n";
76 $via_trait = new CThruTrait();
80 echo '********** null **********', "\n";
84 echo '********** array **********', "\n";
88 echo '********** number **********', "\n";
95 function test_reflection() {
97 '--------------------', ' ', __FUNCTION__
, ' ', '--------------------',
99 var_dump(interface_exists(Stringish
::class));
101 var_dump(is_a(CExplicit
::class, Stringish
::class));
102 var_dump(is_subclass_of(CExplicit
::class, Stringish
::class));
104 var_dump(is_a(CImplicit
::class, Stringish
::class));
105 var_dump(is_subclass_of(CImplicit
::class, Stringish
::class));
107 $rc = new ReflectionClass(CExplicit
::class);
108 var_dump($rc->getInterfaceNames());
109 var_dump($rc->implementsInterface(Stringish
::class));
110 var_dump($rc->isSubclassOf(Stringish
::class));
112 $rc = new ReflectionClass(CImplicit
::class);
113 var_dump($rc->getInterfaceNames());
114 var_dump($rc->implementsInterface(Stringish
::class));
115 var_dump($rc->isSubclassOf(Stringish
::class));
117 $rc = new ReflectionClass(CThruTrait
::class);
118 var_dump($rc->getInterfaceNames());
119 var_dump($rc->implementsInterface(Stringish
::class));
120 var_dump($rc->isSubclassOf(Stringish
::class));
122 $rc = new ReflectionClass(TStringish
::class);
123 var_dump($rc->getInterfaceNames());
124 var_dump($rc->implementsInterface(Stringish
::class));
125 var_dump($rc->isSubclassOf(Stringish
::class));
127 $rc = new ReflectionClass(IStringish
::class);
128 var_dump($rc->getInterfaceNames());
129 var_dump($rc->implementsInterface(Stringish
::class));
130 var_dump($rc->isSubclassOf(Stringish
::class));
134 test_functionality();