Hello,

Is it possible to add Weak References to this todo list?
https://bugs.php.net/bug.php?id=52318

I've been waiting over a year now for this feature. It's a critical part of
object relational layer mapping and my framework will be broken until it
exists. One of our important customer projects also broke down because my
current work around (simply using an array) leaks huge amounts of memory due
to automatic instance caching similar to the one in the example I typed down
below. I'm also considering switching language since PHP lacks this
important OOP concept.

There does not yet seem to be an RFC for it so I typed down an example that
attempts to look like real-word usage here:

http://pastebin.com/pCHVK0L8

I esteimate that it's pretty simple to implement the theoretical
"SplWeakArray" in the example I wrote if you have a bit of knowledge about
the internals of PHP referencing and garbage collection.

See the Java "WeakReference" for conceptual reference.

http://download.oracle.com/javase/1.4.2/docs/api/java/lang/ref/WeakReference.html

A copy of WeakReference would be a partial solution for me since I rather
need a dictionary of id's mapped to objects. I don't want to go trough an
array all the time and look for indexes that has been set to NULL. That's
the GCs job. Hence the SplWeakArray class.

~Hannes

Reply via email to