Skip to content

Commit c3616e7

Browse files
TysonAndrenicolas-grekas
authored andcommitted
Add a polyfill for the Attribute class
Code which works with both php 7 and 8 may need to use the class constants or instances of the class outside of attribute declarations. E.g. // This line throws without a polyfill for Attribute. const FUNCTIONLIKE_ATTRIBUTES = Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD; #[Attribute(FUNCTIONLIKE_ATTRIBUTES)] function example() { } For #235
1 parent d87d576 commit c3616e7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Resources/stubs/Attribute.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
#[Attribute(Attribute::TARGET_CLASS)]
4+
final class Attribute
5+
{
6+
const TARGET_CLASS = 1;
7+
const TARGET_FUNCTION = 2;
8+
const TARGET_METHOD = 4;
9+
const TARGET_PROPERTY = 8;
10+
const TARGET_CLASS_CONSTANT = 16;
11+
const TARGET_PARAMETER = 32;
12+
const TARGET_ALL = 63;
13+
const IS_REPEATABLE = 64;
14+
15+
/** @var int */
16+
public $flags;
17+
18+
public function __construct(int $flags = Attribute::TARGET_ALL)
19+
{
20+
$this->flags = $flags;
21+
}
22+
}

0 commit comments

Comments
 (0)