|
|
|
|
|
by NaN1352
1671 days ago
|
|
Can you directly cast an object / assoc array to an instance of such a class? If I have a function that receives eg a Message, it means an instance of the class right? So somehow my assoc.array/object still needs to be instanced, and if I do just $message = new Message($theData) … it doesn’t auto assign properties right? That would be handy though still very much boilerplate. I guessthe language is just designed for how it’s been used so far, may e it will change if JIT makes php more open ended in its uses. |
|
Anyway I was curious so I wanted to try this out with the trait method here is working code that illustrates this.
EDIT: Added ugly check to make sure the type can be iterated over.