Q:

How to detect an instance of an anonymous class?

Since PHP7, we have anonymous classes.
How can we know if an $instance is an instance of an anonymous class?

A:

Using Reflection
$instance = new class {};

$testInstance = new ReflectionClass($instance);
var_dump($testInstance->isAnonymous());

EDIT
Of course, given that you must be running PHP7 for anonymous classes anyway, wrap it up into a one-liner
var_dump((new ReflectionClass($instance))->isAnonymous());

