views:

28

answers:

1

I'm currently developing an Custom Application using the IP.Board framework, which is in PHP, which by default, creates a IPSMember object for the logged-in user. However, I'm developing an additional class, basically

class SpecialUser extends IPSMember

Is there a way to get the parent object, which is IPSMember to change to SpecialUser?

A: 

I'm not certain, but I do not believe there is a way to change the object type internally. At least, I've been unable to have a __construct() return an object of a different class.

The easiest way, perhaps, would be to create a static initializer method in SpecialUser which takes in an IPSMember object and translates the properties, returning a SpecialUser object.

class SpecialUser extends IPSMember
{
    public static function initWithIPSMember (IPSMember $ipsMember)
    {
        $specialUserObj = new SpecialUser();
        // translate any properties     
        return $specialUserObj;
    }
}

The Reflection Class's getproperties method may enable you do to this quickly. http://php.net/manual/en/reflectionclass.getproperties.php

Hopefully someone can offer you a quicker solution. Good luck.

calurion