0

I have below Abstract Class

abstract class AbstractPerson{
  ......
}

I have inherited AbstractPerson into Account

class Account extends AbstractPerson{
  ......
}

Now I am going to make object of class

$account= new Account()

I am wondering how to check $account object is extended from AbstractPerson class?

2 Answers 2

2

Well, you need Reflection, and two methods getParentClass() & isAbstract().

Here's a working example of what you need.

$accountReflection     = new ReflectionClass('Account');
$parentReflection     = new ReflectionClass($accountReflection->getParentClass()->getName());
$isAbstract           = $parentReflection->isAbstract(); // return true of false
Sign up to request clarification or add additional context in comments.

4 Comments

What is $testClass?
I fix it, check it.
$accountReflection::getParentClass(); this syntax is wrong getting error
I have edited accessor, but still $isAbstract returns false;
0

Use:

if ($account instanceof AbstractPerson) {
   echo 'AbstractPerson';
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.