ryunosuke / polyfill-attribute
Emulate php8's attributes
Installs: 98
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/ryunosuke/polyfill-attribute
Requires
- php: >=7.4
 - nikic/php-parser: *
 - psr/simple-cache: *
 - roave/better-reflection: 4.*|5.*
 
Requires (Dev)
- phpunit/phpunit: 8.*
 
This package is auto-updated.
Last update: 2025-10-18 08:15:54 UTC
README
Description
This package provides attribute feature of php8 and later.
Install
{
    "require": {
        "ryunosuke/polyfill-attribute": "*"
    }
}
Demo
# Below are the same results
php74 demo/main.php
php80 demo/main.php
Usage
The Provider class provides a method that returns a ReflectionAttribute.
This works the same way in php7/8.
Notice
- Performance is low
 - Attributes are cached per identifier if a PSR16 is specified
 - Abstract syntax tree is cached per filename
 - There are minute differences in 
__CLASS__of anonymous classes - Not support continuous line attribute (e.g. 
#[Attribute] private $property) - Attribute::$target constraint is a runtime error (in php8 it is compile time)
 
Release
@api method Versioning follows semantic versioning.
- https://semver.org
- major: change specifications (BC break)
 - minor: add feature (no BC break)
 - patch: fix bug (no BC break)
 
 
2.0.0
- [feature] delete utility getter
- use ryunosuke/utility-attribute (https://github.com/arima-ryunosuke/php-utility-attribute)
 
 - [feature] deprecated No cache setting
 
1.2.0
- [feature] support BetterReflection attribute
 - [feature] support both BetterReflection 4/5
 
1.1.0
- [feature][Provider] add cache per instance
 
1.0.0
- publish
 
License
MIT