I think what should happen in this case is that we should assign the default value to the field, but leave the __isset marker as false. This way if someone wishes to explicitly check for its presence, the isset will properly reflect what was in the serialized data, but the default value can still be freely used.
Do you think that'll still cause weird situations? -----Original Message----- From: Bryan Duxbury [mailto:[email protected]] Sent: Thursday, December 18, 2008 11:23 AM To: [email protected] Subject: Make default values for optional fields illegal? I was thinking a little bit about the potentially hairy situation of trying to deserialize a struct that has optional fields with default values. The problem that could happen is that the optional field is omitted from the serialized data, but once you're done reading, you find your struct has a value for that field. I guess some people might appreciate this situation, but personally, I think it would lead to weird inconsistencies. However, if we made the compiler throw errors when you try to assign a default value to an optional field, then this problem could never happen. Required fields would have to be present from the get go or you'd get serialization errors, so there's no risk of running into this problem. What does everyone think about this option? -Bryan
