diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index ca871ef0..f01f397c 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -6064,6 +6064,9 @@ class CompilerBase extends \PhpAot\Core\Translator } // 保护方法,只能当前类和子类使用 if ($flags & Modifiers::PROTECTED) { + if (!$this->classDef) { + return false; + } return $this->isInheritedFrom($this->classDef->getNamespacedName(false), $classDef->getNamespacedName(false)); } // 类外部调用,只允许调用 public 方法 diff --git a/src/Php/Generator/Utils.php b/src/Php/Generator/Utils.php index b2b7528f..b86511eb 100644 --- a/src/Php/Generator/Utils.php +++ b/src/Php/Generator/Utils.php @@ -28,7 +28,7 @@ trait Utils } } - protected function genCharPtr(string $str, bool $escape = false): string + public function genCharPtr(string $str, bool $escape = false): string { return '"' . ($escape ? $this->escapeString($str) : $str) . '"'; } @@ -48,7 +48,7 @@ trait Utils return 'R"(' . $str . ')"'; } - protected function escapeString(string $str): string + public function escapeString(string $str): string { $str = addcslashes($str, "\\\"\n\r\t\v\f\0\x01..\x1f\x7f..\xff"); // C++ trigraph diff --git a/src/gen_stub.php b/src/gen_stub.php index 722b6eb8..a4b68a5a 100755 --- a/src/gen_stub.php +++ b/src/gen_stub.php @@ -2458,7 +2458,7 @@ class EvaluatedValue } elseif (!($this->expr instanceof String_)) { throw new Exception("Expression at line " . $this->expr->getStartLine() . " must be a scalar string"); } - $expr = preg_replace("/(^'|'$)/", '"', $expr); + $expr = preg_replace("/(^'|'$)/", '"', getTranslator()->escapeString($expr)); } elseif ($this->type->isInt() or $this->type->isFloat()) { return strval($this->value); } elseif ($this->type->isBool()) { diff --git a/tests/aot/object_property/004.phpt b/tests/aot/object_property/004.phpt new file mode 100644 index 00000000..cb488d79 --- /dev/null +++ b/tests/aot/object_property/004.phpt @@ -0,0 +1,24 @@ +--TEST-- +default array property +--FILE-- +x,true); + Assert::isArray($json); + Assert::count($json, 4); + Assert::eq($json[0]['label'], "Option 1"); + echo "DONE\n"; + } +} + +function main() { + require __DIR__ . '/../../../src/Assert.php'; + $obj = new Test; + $obj->bar(); +} +?> +--EXPECT-- +DONE \ No newline at end of file