PHP code example of entire-studio / dynamic-accessors
1. Go to this page and download the library: Download entire-studio/dynamic-accessors 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/ */
entire-studio / dynamic-accessors example snippets
use EntireStudio\DynamicAccessors\{
DynamicAccessors,
Get,
Set
};
/**
* You can annotate your class for IDE completion
* @method void setLastName(string $name)
* @method string getLastName()
*/
class Example {
use DynamicAccessors;
#[Set, Get] // Register default accessors
private string $firstName;
#[Set('setLastName'), Get('getLastName')] // Register under different name
private string $lastName;
}
$e = new Example();
$e->firstName('Clark');
$e->setLastName('Kent');
printf(
'My name is %s %s.' . PHP_EOL,
$e->firstName(), // getter and setter have the same name
$e->getLastName() // getter is custom and different from setter
);
bash
$ php example.php