diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index e2dc837a..ad9855cc 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -2672,7 +2672,7 @@ class CompilerBase extends \PhpAot\Core\Translator return $this->parseAssignOp($expr, '&='); } - private function parseAssignOpBitwiseOr(Expr\AssignOp\BitwiseOr $expr): string + protected function parseAssignOpBitwiseOr(Expr\AssignOp\BitwiseOr $expr): string { return $this->parseAssignOp($expr, '|='); } @@ -2682,7 +2682,7 @@ class CompilerBase extends \PhpAot\Core\Translator return $this->parseAssignOp($expr, '**='); } - protected function error(string $msg): never + public function error(string $msg): never { if ($this->forTest) { throw new TestError($msg); diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 720ecbe7..17a3e95e 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -426,7 +426,7 @@ class Translator extends Preprocessor exit(1); } } - $file = $this->getBuildDir() . '/extension-' . $this->getModuleName() . '.cc'; + $file = $this->getBuildDir() . '/extension-' . $this->targetName . '.cc'; $this->localHeaders = $this->argInfoHeaderFiles; $this->genClassCeList(); $this->indentLevel++; diff --git a/src/gen_stub.php b/src/gen_stub.php index bf18b7aa..66cb054b 100755 --- a/src/gen_stub.php +++ b/src/gen_stub.php @@ -3397,6 +3397,9 @@ class AttributeInfo { } } if ($initValue === '') { + if ($arg->value instanceof Expr\Array_ && count($arg->value->items) > 0) { + getTranslator()->error("Array arguments to attributes are not supported"); + } $value = EvaluatedValue::createFromExpression($arg->value, null, null, $allConstInfos); $code .= $value->initializeZval( "attribute_{$escapedAttributeName}_{$nameSuffix}->args[$i].value", diff --git a/tests/aot/attribute/001.phpt b/tests/aot/attribute/001.phpt new file mode 100644 index 00000000..c3d32c52 --- /dev/null +++ b/tests/aot/attribute/001.phpt @@ -0,0 +1,72 @@ +--TEST-- +Attribute: 001 +--FILE-- +value = $value; + } +} + +#[MyAttribute] +#[MyAttribute(1234)] +#[MyAttribute(value: 1234)] +#[MyAttribute(MyAttribute::VALUE)] +#[MyAttribute([])] +#[MyAttribute(100 + 200)] +class Thing +{ +} + +#[MyAttribute(1234), MyAttribute(5678)] +class AnotherThing +{ +} + +function main() { + $reflection = (new ReflectionClass(Thing::class)); + $attributes = $reflection->getAttributes(); + + foreach ($attributes as $attribute) { + var_dump($attribute->getName()); + var_dump($attribute->getArguments()); + } +} +?> +--EXPECT-- +string(11) "MyAttribute" +array(0) { +} +string(11) "MyAttribute" +array(1) { + [0]=> + int(1234) +} +string(11) "MyAttribute" +array(1) { + ["value"]=> + int(1234) +} +string(11) "MyAttribute" +array(1) { + [0]=> + string(5) "value" +} +string(11) "MyAttribute" +array(1) { + [0]=> + array(0) { + } +} +string(11) "MyAttribute" +array(1) { + [0]=> + int(300) +} \ No newline at end of file diff --git a/tests/aot/attribute/002.phpt b/tests/aot/attribute/002.phpt new file mode 100644 index 00000000..f88008bc --- /dev/null +++ b/tests/aot/attribute/002.phpt @@ -0,0 +1,29 @@ +--TEST-- +Attribute: 002 +--FILE-- +getAttributes(MyAttribute::class); + var_dump($attributes); +} +?> +--EXPECT-- +object(Thing)#1 (0) { +} +array(1) { + [0]=> + object(ReflectionAttribute)#3 (1) { + ["name"]=> + string(11) "MyAttribute" + } +} \ No newline at end of file diff --git a/tests/aot/attribute/003.phpt b/tests/aot/attribute/003.phpt new file mode 100644 index 00000000..49ab0988 --- /dev/null +++ b/tests/aot/attribute/003.phpt @@ -0,0 +1,34 @@ +--TEST-- +Attribute: 003 +--SKIPIF-- + +--FILE-- +getAttributes(MyAttribute::class); + foreach ($attributes as $attribute) { + var_dump($attribute->getName()); + var_dump($attribute->getArguments()); + } +} +?> +--EXPECT-- +object(Thing)#1 (0) { +} +array(1) { + [0]=> + object(ReflectionAttribute)#3 (1) { + ["name"]=> + string(11) "MyAttribute" + } +} \ No newline at end of file