@@ -38,8 +38,7 @@ public static function preload(array $classes)
3838 $ prev = $ classes ;
3939 foreach ($ classes as $ c ) {
4040 if (!isset ($ preloaded [$ c ])) {
41- $ preloaded [$ c ] = true ;
42- self ::doPreload ($ c );
41+ self ::doPreload ($ c , $ preloaded );
4342 }
4443 }
4544 $ classes = array_merge (get_declared_classes (), get_declared_interfaces (), get_declared_traits ());
@@ -49,12 +48,14 @@ public static function preload(array $classes)
4948 }
5049 }
5150
52- private static function doPreload (string $ class )
51+ private static function doPreload (string $ class, array & $ preloaded )
5352 {
54- if (\in_array ($ class , ['self ' , 'static ' , 'parent ' ], true )) {
53+ if (isset ( $ preloaded [ $ class ]) || \in_array ($ class , ['self ' , 'static ' , 'parent ' ], true )) {
5554 return ;
5655 }
5756
57+ $ preloaded [$ class ] = true ;
58+
5859 try {
5960 $ r = new \ReflectionClass ($ class );
6061
@@ -68,7 +69,7 @@ private static function doPreload(string $class)
6869 if (\PHP_VERSION_ID >= 70400 ) {
6970 foreach ($ r ->getProperties () as $ p ) {
7071 if (($ t = $ p ->getType ()) && !$ t ->isBuiltin ()) {
71- self ::doPreload ($ t ->getName ());
72+ self ::doPreload ($ t ->getName (), $ preloaded );
7273 }
7374 }
7475 }
@@ -79,17 +80,17 @@ private static function doPreload(string $class)
7980 $ c = $ p ->getDefaultValueConstantName ();
8081
8182 if ($ i = strpos ($ c , ':: ' )) {
82- self ::doPreload (substr ($ c , 0 , $ i ));
83+ self ::doPreload (substr ($ c , 0 , $ i ), $ preloaded );
8384 }
8485 }
8586
8687 if (($ t = $ p ->getType ()) && !$ t ->isBuiltin ()) {
87- self ::doPreload ($ t ->getName ());
88+ self ::doPreload ($ t ->getName (), $ preloaded );
8889 }
8990 }
9091
9192 if (($ t = $ m ->getReturnType ()) && !$ t ->isBuiltin ()) {
92- self ::doPreload ($ t ->getName ());
93+ self ::doPreload ($ t ->getName (), $ preloaded );
9394 }
9495 }
9596 } catch (\ReflectionException $ e ) {
0 commit comments