Is A Data Object Supposed To Allow The Setting Of Arbitrary Fields? #804
Unanswered
TheFerrettDeveloper
asked this question in
Q&A
Replies: 1 comment
-
That's valid behavior because PHP allows it for every object. In PHP 9 this behavior is removed. For now you could overwrite the __set and __get methods to throw exceptions. Not something I'm going to add in the package since we try to stick to PHP default behaviour. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Maybe I'm misunderstanding the way Spatie-Data's supposed to work, but I would have expected setting a field that's not an object property would throw some kind of error - or at the very least, not allow to access it. (Admittedly, this doesn't return the new field when you toArray() or dump the object as a whole, and it has the same behavior if you put asfdasfd into the validateAndCreate() array - though it doesn't throw an error for having asfdasfd, it just silently discards.)
Is there a way to prevent unauthorized fields from being set in case someone makes a typo, et al? Or is this expected Spatie-Data behavior?
Beta Was this translation helpful? Give feedback.
All reactions