I have following php class
class User implements IUser
{
public function __construct($i_objParent = NULL)
{
}
}
When I login successfully I create object of User class.
There is another class named Student class as follows which extends User Class
class Student extends User
{
public function __construct($i_objParent = NULL)
{
parent::construct($i_objParent);
}
}
Now as I said eariler I already have object of User class how can I construct Student object from existing User Class.
I think it may be possible by passing existing User class object to constructor of child class here Student class object?
Also, Is above approach OK?
As you cannot cast objects in php ( well there are really ugly hacks that work, but i would avoid them ).
Instead there are two ways:
Userinstance in returns you newStudentinstance with all the data transferedUserinstanceActually there is third way ( one that i would use ) : do not do this.
PHP is not the language for DCI development paradigm. IMHO this whole construction makes no sense.
UserandStudentare not interchangeable.