# Weak references - object destruction callback?

- Thread: https://externals.io/message/45181
- Original archive: https://news-web.php.net/php.internals/45181
- Started by Oskar Eisemuth on 2009-08-02T19:08:35+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #45181 — Oskar Eisemuth — 2009-08-02T19:08:35+00:00

URL: https://externals.io/message/45181#45181

Hi

I try to write a a weak reference extension for php5.3 to break circular 
object structures,
so far I have a test implementation that seems to work fine with my 
first tests.

My current system uses a new base class that returns a new resource via 
a getWeakRef method.

This resource can be converted back to a new zval pointing to the 
object, or returning false if the object already is destroyed. So far so 
good, basic tests seems to work correct, the zend engine doesn't get 
screwed.

But general I would want to avoid using a base class all together, is 
there any way to get notified when a object gets out of scope (preferred 
without changing Zend internals)?
I couldn't find a good answer by reading the code, changing the handler 
tables on the fly doesn't feel like the right solution. I am curious 
what is the purpose of the zend_objects_proxy apis?

Converting resources directly to an object by type cast would be nice 
and would avoid using a function for this, could this made somehow possible?

regards
Oskar
