diff --git a/src/PhpGenerator/Factory.php b/src/PhpGenerator/Factory.php index 392455b8..979ca1c7 100644 --- a/src/PhpGenerator/Factory.php +++ b/src/PhpGenerator/Factory.php @@ -272,7 +272,7 @@ public function fromPropertyReflection(\ReflectionProperty $from): Property public function fromObject(object $obj): Literal { - return new Literal('new ' . $obj::class . '(/* unknown */)'); + return new Literal('new \\' . $obj::class . '(/* unknown */)'); } diff --git a/tests/PhpGenerator/ClassType.from.phpt b/tests/PhpGenerator/ClassType.from.phpt index 837fb11a..f051b713 100644 --- a/tests/PhpGenerator/ClassType.from.phpt +++ b/tests/PhpGenerator/ClassType.from.phpt @@ -29,5 +29,6 @@ $res[] = ClassType::from(Abc\Class7::class); $res[] = ClassType::from(Abc\Class8::class); $res[] = ClassType::from(Abc\Class9::class); $res[] = ClassType::from(Abc\Class10::class); +$res[] = ClassType::from(Abc\Class11::class); sameFile(__DIR__ . '/expected/ClassType.from.expect', implode("\n", $res)); diff --git a/tests/PhpGenerator/expected/ClassType.from.81.expect b/tests/PhpGenerator/expected/ClassType.from.81.expect index 2200d27e..f52acd06 100644 --- a/tests/PhpGenerator/expected/ClassType.from.81.expect +++ b/tests/PhpGenerator/expected/ClassType.from.81.expect @@ -1,4 +1,4 @@ -#[Attr(new Abc\Attr(/* unknown */))] +#[Attr(new \Abc\Attr(/* unknown */))] class Class11 { final public const FOO = 10; @@ -12,7 +12,7 @@ class Class11 } - public function bar($c = new stdClass(/* unknown */)) + public function bar($c = new \stdClass(/* unknown */)) { } } diff --git a/tests/PhpGenerator/expected/ClassType.from.expect b/tests/PhpGenerator/expected/ClassType.from.expect index b52d045e..23e0d57a 100644 --- a/tests/PhpGenerator/expected/ClassType.from.expect +++ b/tests/PhpGenerator/expected/ClassType.from.expect @@ -152,3 +152,15 @@ class Class10 { } } + +class Class11 +{ + public string|int $prop; + + + public function test( + Class2 $param = new \Abc\Class2(/* unknown */), + Class3 $param2 = new \Abc\Class3(/* unknown */), + ): string|int { + } +} diff --git a/tests/PhpGenerator/expected/Extractor.classes.expect b/tests/PhpGenerator/expected/Extractor.classes.expect index 2ee92a2a..c5f4c230 100644 --- a/tests/PhpGenerator/expected/Extractor.classes.expect +++ b/tests/PhpGenerator/expected/Extractor.classes.expect @@ -162,3 +162,13 @@ class Class10 { } } + +class Class11 +{ + public string|int $prop; + + + function test(Class2 $param = new Class2(), Class3 $param2 = new Class3()): string|int + { + } +} diff --git a/tests/PhpGenerator/fixtures/classes.php b/tests/PhpGenerator/fixtures/classes.php index ae7ba49e..a68b25ff 100644 --- a/tests/PhpGenerator/fixtures/classes.php +++ b/tests/PhpGenerator/fixtures/classes.php @@ -174,3 +174,12 @@ function test(mixed $param): string|int { } } + +class Class11 +{ + public string|int $prop; + + function test(Class2 $param = new Class2(), \Abc\Class3 $param2 = new \Abc\Class3()): string|int + { + } +}