Skip to content

Commit 43874df

Browse files
committed
Add tests for Attribut(flags: )
This doesn't work correctly yet.
1 parent 4543817 commit 43874df

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Named flags parameter for Attribute attribute
3+
--FILE--
4+
<?php
5+
6+
<<Attribute(flags: Attribute::TARGET_CLASS)>>
7+
class MyAttribute {
8+
}
9+
10+
<<MyAttribute>>
11+
function test() {}
12+
13+
(new ReflectionFunction('test'))->getAttributes()[0]->newInstance();
14+
15+
?>
16+
--EXPECTF--
17+
Fatal error: Uncaught Error: Attribute "MyAttribute" cannot target function (allowed targets: class) in %s:%d
18+
Stack trace:
19+
#0 %s(%d): ReflectionAttribute->newInstance()
20+
#1 {main}
21+
thrown in %s on line %d
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Named flags parameter for Attribute attribute (incorrect parameter name)
3+
--FILE--
4+
<?php
5+
6+
// TODO: This should error at compile-time.
7+
<<Attribute(not_flags: Attribute::TARGET_CLASS)>>
8+
class MyAttribute {
9+
}
10+
11+
<<MyAttribute>>
12+
function test() {}
13+
14+
(new ReflectionFunction('test'))->getAttributes()[0]->newInstance();
15+
16+
?>
17+
--EXPECTF--
18+
Fatal error: Uncaught Error: Attribute "MyAttribute" cannot target function (allowed targets: class) in %s:%d
19+
Stack trace:
20+
#0 %s(%d): ReflectionAttribute->newInstance()
21+
#1 {main}
22+
thrown in %s on line %d

Zend/zend_attributes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static HashTable internal_attributes;
2929

3030
void validate_attribute(zend_attribute *attr, uint32_t target, zend_class_entry *scope)
3131
{
32+
// TODO: More proper signature validation: Too many args, incorrect arg names.
3233
if (attr->argc > 0) {
3334
zval flags;
3435

@@ -121,7 +122,6 @@ ZEND_API int zend_get_attribute_value(zval *ret, zend_attribute *attr, uint32_t
121122
return FAILURE;
122123
}
123124

124-
// TODO: Named args.
125125
ZVAL_COPY_OR_DUP(ret, &attr->args[i].value);
126126

127127
if (Z_TYPE_P(ret) == IS_CONSTANT_AST) {

0 commit comments

Comments
 (0)