dgifford/array-access-trait

Trait providing methods to implement array access using a container variable.

Maintainers

👁 dgifford

Package info

bitbucket.org/dgifford/array-access-trait

pkg:composer/dgifford/array-access-trait

Statistics

Installs: 5 696

Dependents: 3

Suggesters: 0

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

Requires

  • php: >=8.1

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

GPL-3.0 c294b1b725439f11ef5a9b258cb3459f183bad8c

  • Dan Gifford

phparraytraitArrayAccess

This package is auto-updated.

Last update: 2026-06-07 18:17:50 UTC


README

Adds the basic methods for accessing properties of an object using array notation.

For example:

$foo = new Foo;

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

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

unset( $foo['bar'] );

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

Properties created in this way are stored in a private array called 'container'.

Any class that uses this trait must implement the ArrayAccess interface, see http://php.net/manual/en/class.arrayaccess.php.

For example:

class Foo implements \ArrayAccess
{
}

Changelog

  • v2.0 PHP 8 Compatibility
  • v1.0 Initial release