PHP code example of koriym / param-reader

1. Go to this page and download the library: Download koriym/param-reader 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/ */

    

koriym / param-reader example snippets


$reader = new PramReader();
$user = $reader->getParametrAnnotation(new ReflectionParameter([Consumer::class, '__construct'], 'name'), User::class);
assert($user instanceof User);

$users = $reader->getParametrAnnotations(new ReflectionParameter([Consumer::class, '__construct'], 'name'));
assert($users[0] instanceof User);
assert($users[1] instanceof Foo);

class Consumer
{
    private $name;
    
    public function __construct(#[User, Foo] string $name) {
        $this->name = $name;
    }
}

class Consumer
{
    /**
     * @User
     * @Foo
     */
    private $name;
    
    public function __construct(string $name) {
        $this->name = $name;
    }
}