fix(php): 修复编译器命名空间转义问题

- 在静态变量前缀中使用 escapeNamespace 方法转义命名空间
- 使用 escapeClass 方法转义类名以防止特殊字符问题
- 使用 escapeName 方法转义最终名称确保安全
- 防止因特殊字符导致的编译错误和命名冲突
pull/1/head
韩天峰 6 months ago
parent 0e0f232571
commit fab6490a85
  1. 6
      src/Php/CompilerBase.php

@ -614,10 +614,10 @@ class CompilerBase extends \PhpAot\Core\Translator
{ {
$prefix = self::STATIC_VAR; $prefix = self::STATIC_VAR;
if ($this->namespace) { if ($this->namespace) {
$prefix .= $this->namespace . '_'; $prefix .= $this->escapeNamespace($this->namespace) . '_';
} }
if ($this->class) { if ($this->class) {
$prefix .= $this->class . '_'; $prefix .= $this->escapeClass($this->class) . '_';
if ($this->method) { if ($this->method) {
$prefix .= $this->method . '_'; $prefix .= $this->method . '_';
} }
@ -626,7 +626,7 @@ class CompilerBase extends \PhpAot\Core\Translator
$prefix .= $this->function . '_'; $prefix .= $this->function . '_';
} }
} }
return $prefix . $name; return $this->escapeName($prefix . $name);
} }
protected function getNamespacedClassName(string $class): string protected function getNamespacedClassName(string $class): string

Loading…
Cancel
Save