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
declare(strict_types=1);
use EntireStudio\DynamicAccessors\{
DynamicAccessors,
Get,
Set
};
/**
* You can annotate your class for IDE completion
*
* @method string|void firstName(?string $argument = '')
* @method void setLastName(string $name)
* @method string getLastName()
*/
class Basic
{
use DynamicAccessors;
#[Set, Get]
private string $firstName;
#[Set('setLastName'), Get('getLastName')]
private string $lastName;
}
$basic = new Basic();
$basic->firstName('Clark');
$basic->setLastName('Kent');
printf(
'My name is %s %s.' . PHP_EOL,
$basic->firstName(),
$basic->getLastName(),
);
declare(strict_types=1);
use EntireStudio\DynamicAccessors\{
DynamicAccessors,
Get,
Set
};
/**
* You can annotate your class for IDE completion
*
* @method string|void firstName(?string $argument = '')
* @method void setLastName(string $name)
* @method string getLastName()
*/
class ConstructorPropertyPromotion
{
use DynamicAccessors;
public function __construct(
#[Set, Get]
private string $firstName,
#[Set('setLastName'), Get('getLastName')]
private string $lastName,
) {
}
}
$cpp = new ConstructorPropertyPromotion(
'Lois',
'Lane'
);
printf(
'My name is %s %s.' . PHP_EOL,
$cpp->firstName(),
$cpp->getLastName(),
);