File tree 3 files changed +34
-2
lines changed
lib/Doctrine/Common/Proxy
tests/Doctrine/Tests/Common/Proxy
3 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -860,15 +860,17 @@ public function __wakeup()$returnTypeHint
860
860
*/
861
861
private function generateCloneImpl (ClassMetadata $ class )
862
862
{
863
- $ hasParentClone = $ class ->getReflectionClass ()->hasMethod ('__clone ' );
863
+ $ reflectionClass = $ class ->getReflectionClass ();
864
+ $ hasParentClone = $ reflectionClass ->hasMethod ('__clone ' );
865
+ $ returnTypeHint = $ hasParentClone ? $ this ->getMethodReturnType ($ reflectionClass ->getMethod ('__clone ' )) : '' ;
864
866
$ inheritDoc = $ hasParentClone ? '{@inheritDoc} ' : '' ;
865
867
$ callParentClone = $ hasParentClone ? "\n parent::__clone(); \n" : '' ;
866
868
867
869
return <<<EOT
868
870
/**
869
871
* $ inheritDoc
870
872
*/
871
- public function __clone()
873
+ public function __clone() $ returnTypeHint
872
874
{
873
875
\$this->__cloner__ && \$this->__cloner__->__invoke( \$this, '__clone', []);
874
876
$ callParentClone }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Doctrine \Tests \Common \Proxy ;
4
+
5
+ class Php8MagicCloneClass
6
+ {
7
+ public function __clone (): void
8
+ {
9
+ }
10
+ }
Original file line number Diff line number Diff line change @@ -405,6 +405,26 @@ public function testFinalClassThrowsException()
405
405
$ proxyGenerator ->generateProxyClass ($ this ->createClassMetadata (FinalClass::class, []));
406
406
}
407
407
408
+ /**
409
+ * @requires PHP >= 8.0.0
410
+ */
411
+ public function testPhp8CloneWithVoidReturnType ()
412
+ {
413
+ $ className = Php8MagicCloneClass::class;
414
+
415
+ if ( ! class_exists ('Doctrine\Tests\Common\ProxyProxy\__CG__\Php8MagicCloneClass ' , false )) {
416
+ $ metadata = $ this ->createClassMetadata ($ className , ['id ' ]);
417
+
418
+ $ proxyGenerator = new ProxyGenerator (__DIR__ . '/generated ' , __NAMESPACE__ . 'Proxy ' );
419
+ $ this ->generateAndRequire ($ proxyGenerator , $ metadata );
420
+ }
421
+
422
+ self ::assertStringContainsString (
423
+ 'public function __clone(): void ' ,
424
+ file_get_contents (__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp8MagicCloneClass.php ' )
425
+ );
426
+ }
427
+
408
428
/**
409
429
* @requires PHP >= 8.0.0
410
430
*/
You can’t perform that action at this time.
0 commit comments