NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
what is a "soft reference"?


Joined: 10 Jan 2005
Posts: 9
Reply with quote
I am using PHP 4.3.9 on Windows XP Pro.

In PHPed, when I mouse over a value in Debug mode I keep seeing the words "soft reference" but I can't find any information about this online.

What does this mean? It seems like I get it by doing stuff like this:

$aValue = $inputValue;
$bValue = $inputValue;

Then $bValue will show up later in a parent function as a soft reference.

Any ideas?

Thanks!

-David
View user's profileFind all posts by david102299Send private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
it means that this variable refers to another variable.
View user's profileFind all posts by dmitriSend private messageVisit poster's website
??


Joined: 10 Jan 2005
Posts: 9
Reply with quote
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.
View user's profileFind all posts by david102299Send private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
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.
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Can't check value of a "soft reference"


Joined: 26 Jul 2006
Posts: 6
Reply with quote
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
View user's profileFind all posts by ksmootSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
Could you please post a sample and screenshot of that?
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Sample code with soft reference


Joined: 26 Jul 2006
Posts: 6
Reply with quote
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
View user's profileFind all posts by ksmootSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
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
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 23 Sep 2005
Posts: 6
Reply with quote
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 ..
View user's profileFind all posts by K.LondenbergSend private message


Joined: 18 Oct 2006
Posts: 75
Reply with quote
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
View user's profileFind all posts by nickweaversSend private messageVisit poster's websiteYahoo Messenger


Joined: 09 Dec 2003
Posts: 92
Reply with quote
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.
View user's profileFind all posts by mpSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
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
View user's profileFind all posts by dmitriSend private messageVisit poster's website
what is a "soft reference"?
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic