Edit report at https://bugs.php.net/bug.php?id=57201&edit=1

 ID:                 57201
 Updated by:         col...@php.net
 Reported by:        wb at pro-net dot co dot uk
 Summary:            SplObject[Weak]Reference proposal
-Status:             Open
+Status:             Closed
 Type:               Feature/Change Request
-Package:            SPL
+Package:            *General Issues
 Operating System:   *
 PHP Version:        5.*
-Assigned To:        helly
+Assigned To:        colder
 Block user comment: N
 Private report:     N

 New Comment:

Seems that what you are looking for is:

https://github.com/colder/php-weakref


Previous Comments:
------------------------------------------------------------------------
[2006-09-01 05:35:25] wb at pro-net dot co dot uk

Pardon my ignorance but I have no idea what you mean when you say JNI.

The main functionality I'm looking for is to simply (from a PHP point of view) 
be able to link objects to /any/ existing object without having to do or worry 
about the following:

   1. Amend the existing class declarations.
   2. Having to manually implement some kind of 'garbage collection' when your 
holding object is the only object left with references to the base objects. As 
far as I can see this can not be done from within a php script.

Just thinking off the top of my head but this could probably be linked in with 
the recent __toHash() debate on the internals list. If the __toHash() 
functionality was available along with an object_hash_exists($hashString) 
function then the functionality could be implemented from within a php script. 
You wouldn't have automatic GC but you could then provide a cleanUp() method 
that you could call to check that the object hashes exist and then act 
accordingly. Also depending on how the GC works internally you might also be 
able to provide a register_gc_function($callback) so that the cleanUp() method 
get called whenever the PHP GC is actioned.

As for the example I posted, I was using stdClsss as a way to ensure that only 
objects are allowed to be passed to the class methods. Off topic but is there a 
better way to do this or should I just leave out the type hinting and do an 
is_object($foo) check within the method?

I have already created a php land class that extends SplObjectStorage that only 
works on given classes or interfaces, however this does not help with the 
request in hand, although it is useful in its own right.

------------------------------------------------------------------------
[2006-08-31 21:30:48] he...@php.net

Your weak reference sounds very much like JNI. In our case we could eventually 
do it but we pretty much do not have something to hook into the garbage 
collection to get rid of otherwise no longer used objects.

A question from my side is whether you want some template/generic solution here 
or something else. In your example code you had stdClsss as base class but you 
must remember that not all PHP classes derive from that class. Actually we have 
no common base class at all. Which basically brings us back to the 
template/generic solution.

What we could do is provide a function that creates a class derived from 
SplObjectStorage that only works on a given class or interface. Would that 
solve what you want?

------------------------------------------------------------------------
[2006-08-29 05:03:38] wb at pro-net dot co dot uk

Description:
------------
This is just a request for a new SPL class. Its similar to the  
SplObjectStorage class but allows you to provide a base class to reference 
against.

The reasoning behind this is that you might have a situation where you 
want/need to assign other objects to a specific object instance without having 
to amend any existing objects and without the objects needing knowing about it. 

An example could be a generic permission system where you have an object and 
using this new class you assign a permission reference to it which you can then 
check at a later time.

Reproduce code:
---------------
Reference implementation and simple example available at...

http://wb.pro-net.co.uk/php/splobjectreference.phps

Expected result:
----------------
N/A

Actual result:
--------------
N/A


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=57201&edit=1

Reply via email to