Skip to content

Commit 7521233

Browse files
committed
fix Extender finding extension method for subclass
1 parent a90f9ed commit 7521233

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/Extender.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,27 @@ public static function getImports(object $target): array
4444
$count = 0;
4545
$trace = debug_backtrace();
4646
foreach ($trace as $info) {
47-
$class = $info['class'] ?? null;
48-
$function = $info['function'] ?? null;
49-
// Looking for the file where the target calls the method __call().
50-
if ($class == get_class($target) && $function == '__call') {
51-
$file = $info['file'] ?? '';
52-
break;
47+
$object = $info['object'] ?? null;
48+
if ($object) {
49+
// Looking for the file where the target object calls the method __call().
50+
$function = $info['function'] ?? null;
51+
if ($object::class == $target::class && $function == '__call') {
52+
$file = $info['file'] ?? '';
53+
break;
54+
}
5355
}
5456
$count++;
5557
}
5658

57-
$classes = self::$classes[$file] ?? [];
59+
$classes = static::$classes[$file] ?? [];
5860
// Return the imports if they are already stored.
5961
if ($classes) return $classes;
6062

6163
// Add the case where the extension method used inside the extension class.
6264
$callerClass = $trace[$count + 1]['class'] ?? null;
6365
if ($callerClass) {
6466
$classes[] = $callerClass;
65-
self::$classes[$file] = $classes;
67+
static::$classes[$file] = $classes;
6668
}
6769

6870
// Looking for all the imports in the file.
@@ -71,7 +73,7 @@ public static function getImports(object $target): array
7173
preg_match_all("%(?i)use\s+([A-Za-z_\\\]+);%", $contents, $matches);
7274
if (isset($matches[1])) {
7375
$classes = array_merge($classes, $matches[1]);
74-
self::$classes[$file] = $classes;
76+
static::$classes[$file] = $classes;
7577
}
7678
}
7779

0 commit comments

Comments
 (0)