texthtml / object-reaper
Be notified of objects being destroyed
Package info
github.com/texthtml/php-object-reaper
Language:Shell
pkg:composer/texthtml/object-reaper
v1.2.0
2026-11-13 21:13 UTC
Requires
- php: ^8.2
Requires (Dev)
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^10.5
- slevomat/coding-standard: ^8.0
- squizlabs/php_codesniffer: ^4.0
- texthtml/doctest: ^0.3
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-30 02:14:58 UTC
README
Let you register callbacks that will be called when objects are destroyed.
Installation
composer req texthtml/object-reaper
Requires PHP 8.2+.
Usage
$a = (object) []; // Attach a callback to any object // It will be called when the object is destroyed Reaper::watch($a, function () { echo "Good Bye"; }); // "Good bye" will be printed when $a is destroyed
Detaching
Reaper::watch() returns a reaper instance. Call forget() on it to detach
the callback: it will no longer be called when the object is destroyed.
$a = (object) []; $reaper = Reaper::watch($a, function () { echo "Good Bye"; }); $reaper->forget(); unset($a); // prints nothing
Multiple callbacks
You can attach several callbacks to the same object. They are called in the order they were registered.
$a = (object) []; Reaper::watch($a, function () { echo "Good"; }); Reaper::watch($a, function () { echo " Bye"; }); unset($a); // prints "Good Bye"