xero-php
xero-php copied to clipboard
Initialise all properties when a new model is constructed
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
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?
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 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?