Chris@13: Chris@13: */ Chris@13: class InstanceOfPass extends CodeCleanerPass Chris@13: { Chris@13: const EXCEPTION_MSG = 'instanceof expects an object instance, constant given'; Chris@13: Chris@13: /** Chris@13: * Validate that the instanceof statement does not receive a scalar value or a non-class constant. Chris@13: * Chris@13: * @throws FatalErrorException if a scalar or a non-class constant is given Chris@13: * Chris@13: * @param Node $node Chris@13: */ Chris@13: public function enterNode(Node $node) Chris@13: { Chris@13: if (!$node instanceof Instanceof_) { Chris@13: return; Chris@13: } Chris@13: Chris@13: if (($node->expr instanceof Scalar && !$node->expr instanceof Encapsed) || $node->expr instanceof ConstFetch) { Chris@13: throw new FatalErrorException(self::EXCEPTION_MSG, 0, E_ERROR, null, $node->getLine()); Chris@13: } Chris@13: } Chris@13: }