File tree Expand file tree Collapse file tree 2 files changed +65
-0
lines changed
tests/PHPStan/Rules/Classes Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -499,4 +499,34 @@ public function testBug10248(): void
499499 $ this ->analyse ([__DIR__ . '/data/bug-10248.php ' ], []);
500500 }
501501
502+ public function testClassString (): void
503+ {
504+ $ this ->analyse ([__DIR__ . '/data/class-string.php ' ], [
505+ [
506+ 'Parameter #1 $i of class ClassString\A constructor expects int, string given. ' ,
507+ 21 ,
508+ ],
509+ [
510+ 'Parameter #1 $i of class ClassString\A constructor expects int, string given. ' ,
511+ 22 ,
512+ ],
513+ [
514+ 'Parameter #1 $i of class ClassString\A constructor expects int, string given. ' ,
515+ 23 ,
516+ ],
517+ [
518+ 'Parameter #1 $i of class ClassString\A constructor expects int, string given. ' ,
519+ 26 ,
520+ ],
521+ [
522+ 'Parameter #1 $i of class ClassString\A constructor expects int, string given. ' ,
523+ 27 ,
524+ ],
525+ [
526+ 'Parameter #1 $i of class ClassString\A constructor expects int, string given. ' ,
527+ 29 ,
528+ ],
529+ ]);
530+ }
531+
502532}
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace ClassString ;
4+
5+ class A
6+ {
7+ public $ i ;
8+
9+ public function __construct (int $ i )
10+ {
11+ $ this ->i = $ i ;
12+ }
13+ }
14+
15+ class HelloWorld
16+ {
17+ /**
18+ * @return class-string<A>
19+ */
20+ public static function sayHelloBug (): string
21+ {
22+ return A::class;
23+ }
24+ }
25+
26+ $ classString = HelloWorld::sayHelloBug ();
27+ $ bug = new (HelloWorld::sayHelloBug ())('O_O ' );
28+ $ bug = new ($ classString )('O_O ' );
29+ $ bug = new $ classString ('O_O ' );
30+
31+ $ className = A::class;
32+ $ ok = new ($ className )('O_O ' );
33+ $ ok = new $ className ('O_O ' );
34+
35+ $ ok = new A ('O_O ' );
You can’t perform that action at this time.
0 commit comments