Can I use an instance variable as the key for an associative array?
The array is an instance variable of the same object. I want to keep track about what instance variable has changed it's value, so it seems to be a simple solution to pass the instance variab开发者_高级运维le itself as an key to an associative array.
Is this perfectly fine with PHP or does this have some bad side effects?
You can't; the key must be a scalar. See the manual. Depending on the scenario, one solution might be to associate an index with the objects in question, and then use this index for the array, or you could have for each value an object/array containing the object in question, and whatever information you want to associate with it.
Keys of arrays can only be strings or integers.
精彩评论