Chris@13: atLeastPhp55 = \version_compare(PHP_VERSION, '5.5', '>='); Chris@13: } Chris@13: Chris@13: /** Chris@13: * Validate use of empty in PHP < 5.5. Chris@13: * Chris@13: * @throws ParseErrorException if the user used empty with anything but a variable Chris@13: * Chris@13: * @param Node $node Chris@13: */ Chris@13: public function enterNode(Node $node) Chris@13: { Chris@13: if ($this->atLeastPhp55) { Chris@13: return; Chris@13: } Chris@13: Chris@13: if (!$node instanceof Empty_) { Chris@13: return; Chris@13: } Chris@13: Chris@13: if (!$node->expr instanceof Variable) { Chris@17: $msg = \sprintf('syntax error, unexpected %s', $this->getUnexpectedThing($node->expr)); Chris@13: Chris@13: throw new ParseErrorException($msg, $node->expr->getLine()); Chris@13: } Chris@13: } Chris@13: Chris@13: private function getUnexpectedThing(Node $node) Chris@13: { Chris@13: switch ($node->getType()) { Chris@13: case 'Scalar_String': Chris@13: case 'Scalar_LNumber': Chris@13: case 'Scalar_DNumber': Chris@17: return \json_encode($node->value); Chris@13: Chris@13: case 'Expr_ConstFetch': Chris@13: return (string) $node->name; Chris@13: Chris@13: default: Chris@13: return $node->getType(); Chris@13: } Chris@13: } Chris@13: }