var instanceof Array_ && !$node->var instanceof List_) { return null; } // Polyfill for PHP-Parser 2.x $items = isset($node->var->items) ? $node->var->items : (\property_exists($node->var, 'vars') ? $node->var->vars : []); if ($items === [] || $items === [null]) { throw new ParseErrorException('Cannot use empty list', ['startLine' => $node->var->getStartLine(), 'endLine' => $node->var->getEndLine()]); } $itemFound = false; foreach ($items as $item) { if ($item === null) { continue; } $itemFound = true; if (!self::isValidArrayItem($item)) { $msg = 'Assignments can only happen to writable values'; throw new ParseErrorException($msg, ['startLine' => $item->getStartLine(), 'endLine' => $item->getEndLine()]); } } if (!$itemFound) { throw new ParseErrorException('Cannot use empty list'); } return null; } /** * Validate whether a given item in an array is valid for short assignment. * * @param Node $item */ private static function isValidArrayItem(Node $item): bool { $value = ($item instanceof ArrayItem || $item instanceof LegacyArrayItem) ? $item->value : $item; while ($value instanceof ArrayDimFetch || $value instanceof PropertyFetch) { $value = $value->var; } // We just kind of give up if it's a method call. We can't tell if it's // valid via static analysis. return $value instanceof Variable || $value instanceof MethodCall || $value instanceof FuncCall; } }