what is a "soft reference"? |
Site Admin
|
it means that this variable refers to another variable.
|
||||||||||||
|
?? |
|
I don't get it...I thought the default behavior of PHP was to make COPIES of variables..? Given my example in the first post, shouldn't both those variables contain copies of the value they were set to? Seems to me that neither should be a soft reference...
Thanks, -David V. |
||||||||||||
|
Site Admin
|
As far as I get, you should not care of when they get splitted into separated copies, so far. Debugger just reflected the fact that they weren't splitted at that time.
|
||||||||||||
|
Can't check value of a "soft reference" |
|
I've searched for information on "soft reference" and found this entry.
The problem that I have with "soft reference" is that when it appears (typically because I've got an array of objects and some of the individual properties of the objects will be listed as "soft reference") I can't check the value of the property. For example, I've got an array of objects, I want to cycle through the objects, checking a property for a value. When the property is listed as "soft reference" I can't check it's value. It comes up as an empty string, even if its been properly set in the code (in a child function of where its value is checked). Any ideas about this? Thanks, Kelley |
||||||||||||
|
Site Admin
|
Could you please post a sample and screenshot of that?
|
||||||||||||
|
Sample code with soft reference |
|
Sorry to have not responded sooner.
I found one way around this issue is make sure the data type of each class member variable is explicitly set when I add a value to the properties of my object. These objects are put into arrays which I use to pass the data around. If the values' type is explicity set, then I will not get a 'soft reference' that does not allow me to compare that value or use it in a meangful way. When I do not set the data type of the property's value explicity each time, I get a soft reference. An example is helpful; here's one from the Immediate window: $daycareReservationList : array = 0: object(DaycareReservationDTO) = daycareReservationId: long = -1 customerId: long = 0 dogId: long = 21 storeId: long = -1 productId: long = 2 userIdFk: long = -1 dateLastUpdated: string = "2006-08-09 18:56:34" activeFlag: long = 1 daycareReservationToStoreAvailableSlotList: array = 1: object(DaycareReservationDTO) = daycareReservationId: soft reference = customerId: long = 0 dogId: long = 10 storeId: soft reference = productId: long = 1 userIdFk: long = -1 dateLastUpdated: soft reference = activeFlag: soft reference = daycareReservationToStoreAvailableSlotList: soft reference = 2: object(DaycareReservationDTO) = daycareReservationId: soft reference = customerId: long = 0 dogId: long = 24 storeId: soft reference = productId: long = 1 userIdFk: long = -1 dateLastUpdated: soft reference = activeFlag: soft reference = daycareReservationToStoreAvailableSlotList: soft reference = Here I have a 3-member array variable called $daycareReservationList. Each member of the array is an object of type DaycareReservationDTO. Notice that several of the members' values are set to 'soft reference =' and no value for those is given. These are values that I have not yet explicity set the data type on. Is this expected behavior? I can word around it, but it is a bit odd. Thanks, Kelley |
||||||||||||
|
Site Admin
|
Dear Kelley,
Why do you care of those "soft refs" at all? In _any_ case a) it's not a phped problem, phped only reflects the facts b) it's not a problem at all b'ze php handles that insternally. So why worry? If by any chance you're oberserving an _inproper_ handling those cases, submit a bug to bugs.php.net |
||||||||||||
|
|
In case you want to inspect an object, I recommend using the "Immediate" tab of the debugger. Just type the expression you are interested in, and you'll
get your answers (No soft references there). If you want complete dumps, use var_dump or var_export there .. |
||||||||||||
|
|
I'm not sure, but this may be something borrowed from Java and its garbage collection scheme. There is an article on it here http://www-128.ibm.com/developerworks/java/library/j-jtp01246.html
|
||||||||||||
|
|
PHP performs copy on write, and if I get Dmitri right "soft reference" means that a variable still shares the value with another one *but* will be split up as soon as you write to it.
It's an implementation detail of the engine, but if you're interested in it, http://www.google.com/search?q=php-ticks-ffm2005.pdf might be worth reading. It has nothing directly to do with garbage collection. "Soft reference" may be misleading because it's also the name for a concept where you can "soft reference" object instances where "soft" means that your reference does not count for GC -- that is, if your "soft" reference is the only reference to an object left than the object may be GC'ted, voiding your reference. |
||||||||||||
|
Site Admin
|
Not sure about being splitted up when needed. It's up to php to do so.
Debugger marks variables as "soft references" when it is sharing value with at least 1 other instance, but has no reference flag. |
||||||||||||
_________________ The PHP IDE team |
what is a "soft reference"? |
|
||
Content © NuSphere Corp., PHP IDE team
Powered by phpBB © phpBB Group, Design by phpBBStyles.com | Styles Database.
Powered by
Powered by phpBB © phpBB Group, Design by phpBBStyles.com | Styles Database.
Powered by