title: Attempt to read property on array
body: <p>i get this error:</p>
  <pre><code>Warning: Attempt to read property &quot;squadra&quot; on array in C:\xampp\htdocs\statistiche-calcio\index.php on line 57
  </code></pre>
  <p>this is the code of my db.php file:</p>
  <pre><code>    &lt;?php
  
  function connect($dbHost, $dbName, $dbUsername, $dbPassword){
  
      $db = new mysqli(
          $dbHost, 
          $dbUsername, 
          $dbPassword, 
          $dbName
      );
  
      if($db-&gt;connect_error){
          die(&quot;Impossibile connettersi al database \n&quot; . $db-&gt;connect_error . &quot;\n&quot; . $db-&gt;connect_errno);
      }
      return $db;
  }
  
  
  function fetchAll(mysqli $db, $table){
  
      $data = [];
  
      $sql = &quot;SELECT * FROM $table&quot;;
  
      $results = $db-&gt;query($sql);
  
      if($results-&gt;num_rows &gt; 0){
          while($row = $results-&gt;fetch_object()){
              $data[] = $row;
          }
      }
      return $data;
  }
  
  
  
  function fetchSquadra(mysqli $db, $table, $squadra){
  
      $data = [];
  
      $sql = &quot;SELECT * FROM $table WHERE id = &quot; . $squadra;
  
      $results = $db-&gt;query($sql);
  
      if($results-&gt;num_rows === 1){
          while($row = $results-&gt;fetch_object()){
              $data[] = $row;
          }
              
      }
      return $data;
  }
  </code></pre>
  <p>and this is my index.php where i get the error:</p>
  <pre><code>&lt;?php
  require_once('config.php');
  require_once('db.php');
  
  $db = connect(
      DB_HOST, 
      DB_NAME, 
      DB_USERNAME, 
      DB_PASSWORD,
  );
  
  $records = [];
  
  $records = fetchAll($db, 'partite');
  
  
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;&gt;
      &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
      &lt;title&gt;Document&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;style&gt;
      table, th, td{
          border: 1px solid grey;
          text-align: center;
      }
      &lt;/style&gt;
      &lt;h1&gt;Risultati Premier League&lt;/h1&gt;
      &lt;table&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;ID&lt;/th&gt;
                  &lt;th&gt;Data&lt;/th&gt;
                  &lt;th&gt;Casa&lt;/th&gt;
                  &lt;th&gt;Risultato&lt;/th&gt;
                  &lt;th&gt;Ospite&lt;/th&gt;
                  &lt;th&gt;Risultato 1 tempo&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              &lt;?php
              if(count($records) &gt; 0):
                  foreach($records as $record):
                      $squadra_casa = fetchSquadra($db, 'squadre', $record-&gt;squadra_casa);
                      $squadra_ospite = fetchSquadra($db, 'squadre', $record-&gt;squadra_ospite);
                      
                      ?&gt;
                      &lt;tr&gt;
                          &lt;td&gt;&lt;?php echo $record-&gt;id;?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $record-&gt;data;?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $squadra_casa-&gt;squadra;?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $record-&gt;goal_casa . &quot; - &quot;. $record-&gt;goal_ospite;?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $squadra_ospite-&gt;squadra;?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $record-&gt;goal_casa_1t . &quot; - &quot;. $record-&gt;goal_ospite_1t;?&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;?php
                  endforeach;
              else: ?&gt;
                  &lt;tr&gt;
                      &lt;td colspan=&quot;6&quot;&gt;Non è stata trovata nessuna partita!&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;?php endif ?&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>I have try to var_dump() the variable $squadra_casa and i get this:</p>
  <blockquote>
  <p>array(1) {
  [0]=&gt;
  object(stdClass)#5 (3) {
  [&quot;id&quot;]=&gt;
  string(2) &quot;18&quot;
  [&quot;squadra&quot;]=&gt;
  string(6) &quot;Fulham&quot;
  [&quot;campionato&quot;]=&gt;
  string(1) &quot;1&quot;
  }
  }</p>
  </blockquote>
  <p>but when i try to echo out the $squadra_casa-&gt;squadra property i get the error.</p>
  <p>How can i solve it? What i'm doing wrong?</p>