Change object type
I'm using CodeIgniter.
I have two Objects of type UserLib and stdClass.
When I do this: $UserLib = $stdClass
, th开发者_运维百科e properties os UserLib will receive the stdClass properties because they are the same.
The problem is that the object type is stdClass and I need it to be UserLib
Is it possible?
Thanks in advance
I think this would be best accomplished by making a function that takes transfers all the data you need from the stdClass to the UserLib:
function makeUserLib($user_lib, $std_class)
{
$user_lib->myfirstvar = $std_class->myfirstvar;
$user_lib->mysecondvar = $std_class->mysecondvar;
etc...
}
Also, if you can edit your UserLib class, I'd suggest making this function a method in the class.
精彩评论