xero-php icon indicating copy to clipboard operation
xero-php copied to clipboard

Initialise all properties when a new model is constructed

Open glennschmidt opened this issue 3 years ago • 3 comments

Set collection properties to an empty collection, other properties to null. Prevents an ‘Undefined index’ notice when calling getters.

I've addressed this via the constructor of the base model class, so it doesn't matter if some of the getters already check for isset and others don't. Let me know if you think this approach will do the job, or if it will create other issues.

Resolves #652

glennschmidt avatar Sep 27 '21 09:09 glennschmidt

The problem is when you send the data to Xero, for some endpoints if a property is missing it ignores it, but if a property is NULL, it might delete it or otherwise perform an unwanted update. For example if all the properties are initialised to null and you update an Employee, any attributes not specified will be deleted. I wonder if instead one could use the __isset magic method?

Healyhatman avatar Sep 28 '21 02:09 Healyhatman

I thought that's why we have the $_dirty list. Doesn't it only send properties that have been explictly set (marked as dirty)?

glennschmidt avatar Sep 28 '21 02:09 glennschmidt

@glennschmidt exactly. I think this should be fine. My only thought is about consistency–this leaves specific handling/initialisation in some models, and also leaves the uninitialised indices for non-collection properties.

Thoughts on that?

calcinai avatar Oct 04 '21 05:10 calcinai