cwola / attribute
PHP Attribute(Cwola library).
Installs: 57
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/cwola/attribute
Requires
- php: >=8.0.0
README
PHP Attribute(Cwola library).
Overview
Add "ReadableAttribute" and "WritableAttribute" for PHP.
Requirement
- PHP8.0+
Installation
composer require cwola/attribute
Usage
- Readable
<?php
use Cwola\Attribute\Readable;
class Foo {
use Readable;
/**
* @var string
*/
#[Readable]
protected string $protectedString = 'Protected';
}
class Bar extends Foo {
/**
* @var string
*/
protected string $override = 'OVER RIDE!!';
/**
* {@inheritDoc}
*/
private function __read(string $name): mixed {
return $this->override;
}
}
$foo = new Foo;
echo $foo->protectedString; // Protected
$foo->protectedString = 'modify'; // Error
$custom = new Bar;
echo $custom->protectedString; // OVER RIDE!!
echo $custom->override; // Error