himanshu-m/accessors
最新稳定版本:0.0.2
Composer 安装命令:
composer require himanshu-m/accessors
包简介
Define getter and setter for inaccessible members of a PHP class
关键字:
README 文档
README
Define getter and setter for inaccessible members of a PHP class
Installation
composer require himanshu-m/accessors
Usage
Use the trait in any class to build getter and/or setters for the private and protected properties of the classes. It can also allow instance method which do not accept any arguments to invoked just like using a property of the object.
use Accessors; class AccessorsTest { use Accessors; private string $prop1; private string $prop2; function __construct(string $p1, string $p2) { $this->prop1 = $p1; $this->prop2 = $p2; $this->acccessible("prop1"); // prop2 can also be renamed as readonlyProp for access from outside. $this->readonly("readonlyProp", "prop2"); } } $obj = new AccessorsTest("property1", "property2"); echo $obj->prop1; // property1 $obj->prop1 = "changed prop1"; echo $obj->readonlyProp; // property2 $obj->readonlyProp = "cannot change prop2..."; // Exception: Property 'readonlyProp' of class AccessorsTest is not accessible
统计信息
- 总下载量: 35
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-15