<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From: Michele Locati &lt;michele@locati.it&gt;
Date: Fri, 4 Dec 2020 12:19:31 +0100
Subject: [PATCH] Fix "access array offset on value of type null"

Backport of https://github.com/doctrine/orm/pull/7785

--- a/lib/Doctrine/ORM/PersistentCollection.php
+++ b/lib/Doctrine/ORM/PersistentCollection.php
@@ -448,7 +448,7 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec
      */
     public function count()
     {
-        if ( ! $this-&gt;initialized &amp;&amp; $this-&gt;association['fetch'] === Mapping\ClassMetadataInfo::FETCH_EXTRA_LAZY) {
+        if (! $this-&gt;initialized &amp;&amp; $this-&gt;association !== null &amp;&amp; $this-&gt;association['fetch'] === Mapping\ClassMetadataInfo::FETCH_EXTRA_LAZY) {
             $persister = $this-&gt;em-&gt;getUnitOfWork()-&gt;getCollectionPersister($this-&gt;association);
 
             return $persister-&gt;count($this) + ($this-&gt;isDirty ? $this-&gt;collection-&gt;count() : 0);

--- a/lib/Doctrine/ORM/Query/Parser.php
+++ b/lib/Doctrine/ORM/Query/Parser.php
@@ -461,7 +461,7 @@ class Parser
     public function semanticalError($message = '', $token = null)
     {
         if ($token === null) {
-            $token = $this-&gt;lexer-&gt;lookahead;
+            $token = isset($this-&gt;lexer-&gt;lookahead) ? $this-&gt;lexer-&gt;lookahead : ['position' =&gt; null];
         }
 
         // Minimum exposed chars ahead of token
@@ -528,7 +528,7 @@ class Parser
      */
     private function isMathOperator($token)
     {
-        return in_array($token['type'], array(Lexer::T_PLUS, Lexer::T_MINUS, Lexer::T_DIVIDE, Lexer::T_MULTIPLY));
+        return $token !== null &amp;&amp; in_array($token['type'], array(Lexer::T_PLUS, Lexer::T_MINUS, Lexer::T_DIVIDE, Lexer::T_MULTIPLY));
     }
 
     /**
@@ -543,7 +543,7 @@ class Parser
 
         $this-&gt;lexer-&gt;resetPeek();
 
-        return ($lookaheadType &gt;= Lexer::T_IDENTIFIER &amp;&amp; $peek['type'] === Lexer::T_OPEN_PARENTHESIS);
+        return $lookaheadType &gt;= Lexer::T_IDENTIFIER &amp;&amp; $peek !== null &amp;&amp; $peek['type'] === Lexer::T_OPEN_PARENTHESIS;
     }
 
     /**
@@ -838,7 +838,7 @@ class Parser
     {
         $this-&gt;lexer-&gt;moveNext();
 
-        switch ($this-&gt;lexer-&gt;lookahead['type']) {
+        switch (isset($this-&gt;lexer-&gt;lookahead['type']) ? $this-&gt;lexer-&gt;lookahead['type'] : null) {
             case Lexer::T_SELECT:
                 $statement = $this-&gt;SelectStatement();
                 break;
@@ -1437,7 +1437,7 @@ class Parser
         // We need to check if we are in a IdentificationVariable or SingleValuedPathExpression
         $glimpse = $this-&gt;lexer-&gt;glimpse();
 
-        if ($glimpse['type'] === Lexer::T_DOT) {
+        if ($glimpse !== null &amp;&amp; $glimpse['type'] === Lexer::T_DOT) {
             return $this-&gt;SingleValuedPathExpression();
         }
 
@@ -1481,7 +1481,7 @@ class Parser
                 $expr = $this-&gt;SimpleArithmeticExpression();
                 break;
 
-            case ($glimpse['type'] === Lexer::T_DOT):
+            case $glimpse !== null &amp;&amp; $glimpse['type'] === Lexer::T_DOT:
                 $expr = $this-&gt;SingleValuedPathExpression();
                 break;
 
@@ -2451,10 +2451,11 @@ class Parser
 
         // Peek beyond the matching closing parenthesis ')'
         $peek = $this-&gt;peekBeyondClosingParenthesis();
-
-        if (in_array($peek['value'], array("=",  "&lt;", "&lt;=", "&lt;&gt;", "&gt;", "&gt;=", "!=")) ||
+        if ($peek !== null &amp;&amp; (
+            in_array($peek['value'], array("=",  "&lt;", "&lt;=", "&lt;&gt;", "&gt;", "&gt;=", "!=")) ||
             in_array($peek['type'], array(Lexer::T_NOT, Lexer::T_BETWEEN, Lexer::T_LIKE, Lexer::T_IN, Lexer::T_IS, Lexer::T_EXISTS)) ||
-            $this-&gt;isMathOperator($peek)) {
+            $this-&gt;isMathOperator($peek)
+        )) {
             $condPrimary-&gt;simpleConditionalExpression = $this-&gt;SimpleConditionalExpression();
 
             return $condPrimary;
@@ -2806,11 +2807,11 @@ class Parser
             case Lexer::T_IDENTIFIER:
                 $peek = $this-&gt;lexer-&gt;glimpse();
 
-                if ($peek['value'] == '(') {
+                if ($peek !== null &amp;&amp; $peek['value'] == '(') {
                     return $this-&gt;FunctionDeclaration();
                 }
 
-                if ($peek['value'] == '.') {
+                if ($peek !== null &amp;&amp; $peek['value'] == '.') {
                     return $this-&gt;SingleValuedPathExpression();
                 }
 
@@ -2826,7 +2827,7 @@ class Parser
             default:
                 $peek = $this-&gt;lexer-&gt;glimpse();
 
-                if ($peek['value'] == '(') {
+                if ($peek !== null &amp;&amp; $peek['value'] == '(') {
                     if ($this-&gt;isAggregateFunction($this-&gt;lexer-&gt;lookahead['type'])) {
                         return $this-&gt;AggregateExpression();
                     }
@@ -3167,7 +3168,7 @@ class Parser
 
         $escapeChar = null;
 
-        if ($this-&gt;lexer-&gt;lookahead['type'] === Lexer::T_ESCAPE) {
+        if ($this-&gt;lexer-&gt;lookahead !== null &amp;&amp; $this-&gt;lexer-&gt;lookahead['type'] === Lexer::T_ESCAPE) {
             $this-&gt;match(Lexer::T_ESCAPE);
             $this-&gt;match(Lexer::T_STRING);
 
--- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php
+++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php
@@ -48,11 +48,12 @@ class YamlExporter extends AbstractExporter
         } else {
             $array['type'] = 'entity';
         }
+        $metadataTable = isset($metadata-&gt;table) ? $metadata-&gt;table : ['name' =&gt; null];
 
-        $array['table'] = $metadata-&gt;table['name'];
+        $array['table'] = $metadataTable['name'];
 
-        if (isset($metadata-&gt;table['schema'])) {
-            $array['schema'] = $metadata-&gt;table['schema'];
+        if (isset($metadataTable['schema'])) {
+            $array['schema'] = $metadataTable['schema'];
         }
 
         $inheritanceType = $metadata-&gt;inheritanceType;
@@ -73,20 +74,20 @@ class YamlExporter extends AbstractExporter
             $array['changeTrackingPolicy'] = $this-&gt;_getChangeTrackingPolicyString($metadata-&gt;changeTrackingPolicy);
         }
 
-        if (isset($metadata-&gt;table['indexes'])) {
-            $array['indexes'] = $metadata-&gt;table['indexes'];
+        if (isset($metadataTable['indexes'])) {
+            $array['indexes'] = $metadataTable['indexes'];
         }
 
         if ($metadata-&gt;customRepositoryClassName) {
             $array['repositoryClass'] = $metadata-&gt;customRepositoryClassName;
         }
 
-        if (isset($metadata-&gt;table['uniqueConstraints'])) {
-            $array['uniqueConstraints'] = $metadata-&gt;table['uniqueConstraints'];
+        if (isset($metadataTable['uniqueConstraints'])) {
+            $array['uniqueConstraints'] = $metadataTable['uniqueConstraints'];
         }
 
-        if (isset($metadata-&gt;table['options'])) {
-            $array['options'] = $metadata-&gt;table['options'];
+        if (isset($metadataTable['options'])) {
+            $array['options'] = $metadataTable['options'];
         }
 
         $fieldMappings = $metadata-&gt;fieldMappings;
</pre></body></html>