I've written a simple extension for supporting weak (non-refcounted)
references in PHP, so that object graphs which reference themselves will
function properly. I don't know if this will be useful to anyone else, but
the code for the extension can be found at
http://4.61.245.27/~chrisv/php-ext-weakref.tgz. (Until the DSL line that
I'm in front of decides that it's going to get a new IP address, anyway..)

The extension implements 2 functions:
        resource(weak reference) weakref(object $o): Returns a resource
                representing the input object. The reference is not
                counted against the object, and becomes invalid when the
                refcount of $o becomes 0.
        object weakref_get(resource(weak reference) $r): If the object
                that $r represents is still valid, this increases the
                refcount on the object and returns it. Otherwise it
                returns false.

It should only compile against ZE2, as it needs access to
EG(objects_store) to check and see if an object reference is still valid
or not. (Unless there is some other way of checking to see if an object ID
still exists, which I didn't happen to spot during my quick browsing of
the source.)

It's one of those little things that happens to seem like a good idea
(being able to reference parent objects from a child object is a quite
handy feature at times, especially when working with stuff that looks like
DOM trees and whatnot.)

Chris



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to