PHP code example of biqiang / biphp-properties
1. Go to this page and download the library: Download biqiang/biphp-properties 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/ */
biqiang / biphp-properties example snippets
use Biphp\Properties\PropertyOwner;
class User
{
use PropertyOwner;
protected function specs(): array
{
return [
'id' => $this->IntegerSpec()->readOnly(),
'name' => $this->StringSpec(),
'inviter' => $this->ObjectSpec()->setInstanceOf(User::class),
];
}
}
$user = new User();
// 访问只读属性
echo $user->id;
// 访问可读写属性
$user->name = 'name';
echo $user->name;