Is this the only way to check if an object is an instance of a class, in my case of the DateTime class?
$cls = ReflectionClass("DateTime");
if (! $cls->isInstance( (object) $var ) ) {
// is not an instance
}
It seems a bit heavy to me.
Is this the only way to check if an object is an instance of a class, in my case of the DateTime class?
$cls = ReflectionClass("DateTime");
if (! $cls->isInstance( (object) $var ) ) {
// is not an instance
}
It seems a bit heavy to me.
if ($var instanceof DateTime)
What about instanceof
You can use get_class function like this:
You could try
instanceof
Docs...See also
is_a
Docs: