On Sat, 2004-08-21 at 10:24, Curt Zirzow wrote: > * Thus wrote Robert Cummings: > > On Sat, 2004-08-21 at 00:10, Curt Zirzow wrote: > > > * Thus wrote Robert Cummings: > > > > Hi All, > > > > > > > > I think I'm looking for something that doesn't exist, but just in > > > > case thought I'd check the list. Does anyone know if a PHP function > > > > exists to get the number of references on a given variable's data? I was > > > > hoping to create a way for a factory to automatically recycle resources > > > > without the need for the developer to call some kind of free() method. > > > > If I could get the internal reference count then I'd be able to > > > > determine if it is free by virtue of only 1 reference (the factory). > > > > This is for PHP4 btw, the solution is trivial in PHP5 using destructors. > > > > > > unfortantly there isn't a method to determain this. > > > > > > Be careful with PHP5, i'm not sure if its applicable in your > > > situation, but there does seem to be rumor that php5 objects are > > > assigned by reference, which isn't true: > > > > > > $o1 = new object(); > > > $o2 = $o1; > > > unset($o2); > > > > > > the Object still exists, and the destructor isn't called. > > > > > > vs. > > > > > > $o3 = new object(); > > > $o4 =& $o3; > > > unset($o3); > > Sorry, those unset's should be: > > $o2 = null; > and > $o3 = null; > > It's was to demonstrate that = and =& are *not* the same thing as > one would believe since the term 'assigned by reference' is used.
As exemplified in the sample script I sent in my last response and by the link sent by Hannes Magnusson, in PHP5 the following have identical behaviour: $o1 = new Foo(); $o2 = $o1; // Is same as... $o1 = new Foo(); $o2 =& $o1; This was not true in PHP4 which is what a developer from PHP4 coming to PHP5 needs to be aware of when using objects. Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php