Suppose I have a User class with \'name\' and \'password\' properties, and a \'save\' method. When serializing an object of this class to JSON via json_encode, the method is pro
Maybe the hydration
pattern can be of help.
Basically you instantiate an new empty object (new User()
) and then you fill in the properties with values from the StdClass
object. For example you could have a hydrate
method in User
.
If possible in your case, you can make the User
constructor
accept an optional parameter of type StdClass
and take the values at instantiation.