开发者

Change object type

开发者 https://www.devze.com 2023-03-13 12:39 出处:网络
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 t

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消