From: Vincent Vanwaelscappel Date: Thu, 23 May 2019 17:32:56 +0000 (+0200) Subject: #2783 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=80b85aa7e620812e7aa3fa14e0ec3c4acce850a8;p=cubist_util.git #2783 --- diff --git a/src/Cubist/Util/PHP.php b/src/Cubist/Util/PHP.php index ffd8c4d..8dda805 100644 --- a/src/Cubist/Util/PHP.php +++ b/src/Cubist/Util/PHP.php @@ -17,12 +17,25 @@ class PHP } } + /** + * @param $file + * @return mixed + */ public static function instanciateClassInFile($file) { $classes = get_declared_classes(); include $file; $diff = array_diff(get_declared_classes(), $classes); - $class = reset($diff); - return new $class(); + $class = null; + foreach ($diff as $diffclass) { + if (realpath($file) == realpath(self::getFileDeclaring($diffclass))) { + $class = $diffclass; + break; + } + } + if (null !== $class) { + return new $class(); + } + return null; } }