dgifford/array-access-trait

提供使用容器变量实现数组访问方法的自定义特性。

v2.0 2024-06-07 13:34 UTC

This package is auto-updated.

Last update: 2024-09-07 14:17:35 UTC


README

添加使用数组符号访问对象属性的基本方法。

例如

$foo = new Foo;

$foo['bar'] = 'bar';

echo $foo['bar']; // 'bar'

unset( $foo['bar'] );

var_dump( isset($foo['bar']) ); // 'false'

以这种方式创建的属性存储在名为 'container' 的私有数组中。

任何使用此特性的类必须实现 ArrayAccess 接口,请参阅 https://php.ac.cn/manual/en/class.arrayaccess.php

例如

class Foo implements \ArrayAccess
{
}

变更日志

  • v2.0 PHP 8 兼容性
  • v1.0 初始发布