To introspect an object in a namespace, the class must still be included using the use directive.
use Doctrine\Common\Collections\ArrayCollection; if ($foo instanceof ArrayCollection) { }
or
if ($foo instanceof \Doctrine\Common\Collections\ArrayCollection) { }
As for your attempt to determine what objects use as an array with is_array($foo) .
The function will work only with the array type. However, to check if it can be used as an array, you can use:
if (is_array($foo) || $foo instanceof \ArrayAccess) { } if (is_array($foo) || $foo instanceof \Traversable) { } if (is_array($foo) || ($foo instanceof \ArrayAccess && $foo instanceof \Traversable)) { }
The ArrayCollection class implements both of these interfaces.
source share