PHP code example of cwola / attribute

1. Go to this page and download the library: Download cwola/attribute library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cwola / attribute example snippets




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