2017 © Pedro Peláez
 

library weak-array

Array of weak references.

image

iddqdby/weak-array

Array of weak references.

  • Monday, March 21, 2016
  • by iddqdby
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

WeakArray

Build Status Latest Stable Version Total Downloads License, (*1)

Short description

WeakArray is an array of weak references, based on WeakRef PHP extension (see https://pecl.php.net/package/Weakref)., (*2)

It keeps weak references to objects, allowing them to be garbage-collected when there are no other references present., (*3)

How to install

composer require iddqdby/weak-array

or download the archive, extract it and include file autoload.php., (*4)

Examples

Basic usage

Code

$weak_array = new WeakArray\WeakArray();

$foo = new stdClass();
$bar = new stdClass();
$baz = new stdClass();

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

var_export($weak_array['foo']);
echo "\n";

var_export($weak_array['bar']);
echo "\n";

var_export($weak_array['baz']);
echo "\n";

echo "====\n";

unset($foo);
unset($bar);

var_export($weak_array['foo']);
echo "\n";

var_export($weak_array['bar']);
echo "\n";

var_export($weak_array['baz']);
echo "\n";

Output

stdClass::__set_state(array(
))
stdClass::__set_state(array(
))
stdClass::__set_state(array(
))
====
NULL
NULL
stdClass::__set_state(array(
))

Events

Code

class Observer implements \SplObserver {
    public function update(\SplSubject $event) {
        // $event instanceof WeakArray\Event;
        // see WeakArray\Event class to view all available methods and Event::* constants
        switch ($event->getType()) {
            case WeakArray\Event::OBJECT_SET:
                $event_str = 'set';
                break;
            case WeakArray\Event::OBJECT_UNSET:
                $event_str = 'unset';
                break;
            case WeakArray\Event::OBJECT_DESTRUCTED:
                $event_str = 'destructed';
                break;
        }
        printf("Object %s, key %s\n", $event_str, $event->getKey());
    }
}

$weak_array = new WeakArray\WeakArray();
$observer = new Observer();

$weak_array->attach($observer);

$foo = new stdClass();
$bar = new stdClass();
$baz = new stdClass();

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

unset($foo);

unset($weak_array['bar']);
unset($weak_array['baz']);

Output

Object set, key foo
Object set, key bar
Object set, key baz
Object destructed, key foo
Object unset, key bar
Object unset, key baz

See examples/ and test/ directories for working examples., (*5)

Requirements

  • PHP: 5.5, 5.6, 7.0
  • WeakRef PHP extension: 0.2.6 for PHP 5.5 and PHP 5.6, >=0.3 for PHP 7.0

Homepage

https://iddqdby.github.io/weak-array/, (*6)

Versioning

This project follows the Semantic Versioning principles., (*7)

License

This project is licensed under the MIT License. See LICENSE., (*8)

The Versions

21/03 2016

dev-master

9999999-dev https://github.com/iddqdby/weak-array

Array of weak references.

  Sources   Download

MIT

The Requires

  • ext-weakref ~0.2
  • php ^5.5 || ^7.0

 

The Development Requires

by Sergey Protasevich

array arrays reference references weak weakref weak reference weak references weak array weak arrays weakmap weakarray

21/03 2016

2.0.x-dev

2.0.9999999.9999999-dev https://github.com/iddqdby/weak-array

Array of weak references.

  Sources   Download

MIT

The Requires

  • php ^5.5 || ^7.0
  • ext-weakref ~0.2

 

The Development Requires

by Sergey Protasevich

array arrays reference references weak weakref weak reference weak references weak array weak arrays weakmap weakarray

21/03 2016

v2.0.1

2.0.1.0 https://github.com/iddqdby/weak-array

Array of weak references.

  Sources   Download

MIT

The Requires

  • php ^5.5 || ^7.0
  • ext-weakref ~0.2

 

The Development Requires

by Sergey Protasevich

array arrays reference references weak weakref weak reference weak references weak array weak arrays weakmap weakarray

20/03 2016

v2.0.0

2.0.0.0 https://github.com/iddqdby/weak-array

Array of weak references.

  Sources   Download

MIT

The Requires

  • php ^5.5 || ^7.0
  • ext-weakref ~0.2

 

The Development Requires

by Sergey Protasevich

array arrays reference references weak weakref weak reference weak references weak array weak arrays weakmap weakarray

20/03 2016

1.1.x-dev

1.1.9999999.9999999-dev https://github.com/iddqdby/weak-array

Array of weak references.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0
  • ext-weakref ~0.2

 

The Development Requires

by Sergey Protasevich

array arrays reference references weak weakref weak reference weak references weak array weak arrays weakmap weakarray

20/03 2016

v1.1.1

1.1.1.0 https://github.com/iddqdby/weak-array

Array of weak references.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0
  • ext-weakref ~0.2

 

The Development Requires

by Sergey Protasevich

array arrays reference references weak weakref weak reference weak references weak array weak arrays weakmap weakarray

20/03 2016

v1.1.0

1.1.0.0 https://github.com/iddqdby/weak-array

Array of weak references.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0
  • ext-weakref ~0.2

 

The Development Requires

by Sergey Protasevich

array arrays reference references weak weakref weak reference weak references weak array weak arrays weakmap weakarray

17/03 2016

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/iddqdby/weak-array

Array of weak references.

  Sources   Download

MIT

The Requires

  • php ^5.5 || ^7.0
  • ext-weakref ^0.3

 

The Development Requires

by Sergey Protasevich

weak reference weak references

17/03 2016

v1.0.2

1.0.2.0 https://github.com/iddqdby/weak-array

Array of weak references.

  Sources   Download

MIT

The Requires

  • php ^5.5 || ^7.0
  • ext-weakref ^0.3

 

The Development Requires

by Sergey Protasevich

weak reference weak references

17/03 2016

v1.0.1

1.0.1.0 https://github.com/iddqdby/weak-array

Array of weak references.

  Sources   Download

MIT

The Requires

  • php ^5.5 || ^7.0
  • ext-weakref ^0.3

 

The Development Requires

by Sergey Protasevich

weak reference weak references

17/03 2016

v1.0.0

1.0.0.0 https://github.com/iddqdby/weak-array

Array of weak references.

  Sources   Download

MIT

The Requires

  • php ^5.5 || ^7.0
  • ext-weakref ^0.3

 

The Development Requires

by Sergey Protasevich

weak reference weak references