why not check for ``if (null !== $document && !is_object($document)) {``?
as it is .. arrays and resources would not be caught as incorrect parameters.