diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index adb0f6cf..0f88bf23 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -4193,6 +4193,12 @@ class CompilerBase extends \PhpAot\Core\Translator return $def->flags & Modifiers::PUBLIC; } + protected function isOverrideMethod(string $fullMethodName): bool + { + $fullMethodNameLower = strtolower($fullMethodName); + return isset($this->classMethodOverride[$fullMethodNameLower]) and $this->classMethodOverride[$fullMethodNameLower]; + } + protected function findNativeMethod(CallLike $expr, string $object, string $method): string|false { $nativeFunc = ''; @@ -4215,7 +4221,7 @@ class CompilerBase extends \PhpAot\Core\Translator } // 存在子类同名方法,需要转为动态调用 - if (isset($this->classMethodOverride[$fullMethodName]) and $this->classMethodOverride[$fullMethodName]) { + if ($this->isOverrideMethod($fullMethodName)) { return false; } if ($nativeFunc) { diff --git a/src/Php/Preprocessor.php b/src/Php/Preprocessor.php index 6f0cdd37..e74e2839 100644 --- a/src/Php/Preprocessor.php +++ b/src/Php/Preprocessor.php @@ -122,7 +122,7 @@ class Preprocessor extends CompilerBase if ($call->name instanceof Node\Name) { $name = $call->name->toString(); $this->symbolCallInFile[] = [ - 'name' => $name, + 'name' => strtolower($name), 'file' => $this->file, 'line' => $call->getLine(), ]; @@ -164,7 +164,7 @@ class Preprocessor extends CompilerBase if ($this->stubFile) { $this->nativeFunctions[$name] = $this->parseFunctionDecl($v); } else { - $this->symbolDeclInFile[$name] = $this->file; + $this->symbolDeclInFile[strtolower($name)] = $this->file; } } @@ -181,16 +181,18 @@ class Preprocessor extends CompilerBase { $this->class = $this->parseIdentifier($class->name); $fullClassName = $this->getNamespacedClassName($this->class); + $fullClassNameLower = strtolower($fullClassName); if (!empty($class->extends)) { $this->parentClass = $this->getParentClass($class->extends); + $parentClassLower = strtolower($this->parentClass); $this->symbolCallInFile[] = [ - 'name' => $this->parentClass, + 'name' => $parentClassLower, 'file' => $this->file, 'line' => $class->getLine(), ]; - $this->classExtends[$fullClassName] = $this->parentClass; + $this->classExtends[$fullClassNameLower] = $parentClassLower; } - $this->symbolDeclInFile[$fullClassName] = $this->file; + $this->symbolDeclInFile[$fullClassNameLower] = $this->file; $code = ''; foreach ($class->stmts as $v) { @@ -223,16 +225,17 @@ class Preprocessor extends CompilerBase $this->prepareFunction($v) . PHP_EOL; if ($this->isIdExpr($v->name) or $this->isNameExpr($v->name)) { $fullClassName = $this->getNamespacedClassName($this->class); - $fullName = $fullClassName . '::' . $v->name; - $this->classMethodOverride[$fullName] = false; + $fullMethodName = $fullClassName . '::' . $v->name; + $this->classMethodOverride[strtolower($fullMethodName)] = false; // 查找父类是否有同名方法,递归查找 - while (isset($this->classExtends[$fullClassName])) { - $parentClass = $this->classExtends[$fullClassName]; - $parentMethod = $parentClass . '::' . $v->name; - if (isset($this->classMethodOverride[$parentMethod])) { - $this->classMethodOverride[$parentMethod] = true; + $fullClassNameLower = strtolower($fullClassName); + while (isset($this->classExtends[$fullClassNameLower])) { + $parentClass = $this->classExtends[$fullClassNameLower]; + $parentMethodLower = strtolower($parentClass . '::' . $v->name); + if (isset($this->classMethodOverride[$parentMethodLower])) { + $this->classMethodOverride[$parentMethodLower] = true; } - $fullClassName = $parentClass; + $fullClassNameLower = strtolower($parentClass); } } }