title: How to fix 'xx is not an array' error in php
body: <p>I am new to this and working off a set of instructions from a colleague who is no longer here. We are running drupal 8.7 and recently a list of warnings started popping up when committing code. I can't determine what is wrong with the code as written.</p>
  
  <p><strong>These are the warnings that appear.</strong></p>
  
  <pre><code>[warning] Illegal offset type ProfileExtensionList.php:183
   [warning] Illegal offset type ProfileExtensionList.php:150
   [info] Undefined property: stdClass::$info ProfileExtensionList.php:157
   [warning] array_merge(): Argument #2 is not an array ProfileExtensionList.php:157
   [warning] array_diff(): Argument #1 is not an array ProfileExtensionList.php:157
   [info] Undefined property: stdClass::$info ProfileExtensionList.php:158
   [warning] array_merge(): Argument #2 is not an array ProfileExtensionList.php:158
   [warning] array_diff(): Argument #1 is not an array ProfileExtensionList.php:158
   [warning] array_unique() expects parameter 1 to be array, null given ProfileExtensionList.php:160
   [warning] array_unique() expects parameter 1 to be array, null given ProfileExtensionList.php:161
   [warning] Illegal offset type ProfileExtensionList.php:183
   [warning] Illegal offset type ProfileExtensionList.php:150
   [info] Undefined property: stdClass::$info ProfileExtensionList.php:157
   [warning] array_merge(): Argument #2 is not an array ProfileExtensionList.php:157
   [warning] array_diff(): Argument #1 is not an array ProfileExtensionList.php:157
   [info] Undefined property: stdClass::$info ProfileExtensionList.php:158
   [warning] array_merge(): Argument #2 is not an array ProfileExtensionList.php:158
   [warning] array_diff(): Argument #1 is not an array ProfileExtensionList.php:158
   [warning] array_unique() expects parameter 1 to be array, null given ProfileExtensionList.php:160
   [warning] array_unique() expects parameter 1 to be array, null given ProfileExtensionList.php:161
  </code></pre>
  
  <p><strong>I've opened the ProfileExtensionList.php, but looking at the lines specified I can't determine what is wrong. I've pasted the code, lines 1-186 (not sure if that is too much).</strong></p>
  
  <pre><code>&lt;?php
  
  namespace Drupal\Core\Extension;
  
  /**
   * Provides a list of installation profiles.
   *
   * @internal
   *   This class is not yet stable and therefore there are no guarantees that the
   *   internal implementations including constructor signature and protected
   *   properties / methods will not change over time. This will be reviewed after
   *   https://www.drupal.org/project/drupal/issues/2940481
   */
  class ProfileExtensionList extends ExtensionList {
  
    /**
     * {@inheritdoc}
     */
    protected $defaults = [
      'dependencies' =&gt; [],
      'install' =&gt; [],
      'description' =&gt; '',
      'package' =&gt; 'Other',
      'version' =&gt; NULL,
      'php' =&gt; DRUPAL_MINIMUM_PHP,
      'themes' =&gt; ['stark'],
      'hidden' =&gt; FALSE,
      'base profile' =&gt; '',
      'exclude' =&gt; [],
    ];
  
    /**
     * {@inheritdoc}
     */
    public function getExtensionInfo($extension_name) {
      $all_info = $this-&gt;getAllAvailableInfo();
      if (isset($all_info[$extension_name])) {
        return $all_info[$extension_name];
      }
      throw new \InvalidArgumentException("The {$this-&gt;type} $extension_name does not exist.");
    }
  
    /**
     * Returns a list comprised of the profile, its parent profile if it has one,
     * and any further ancestors.
     *
     * @param string $profile
     *   (optional) The name of profile. Defaults to the current install profile.
     *
     * @return \Drupal\Core\Extension\Extension[]
     *   An associative array of Extension objects, keyed by profile name in
     *   descending order of their dependencies (ancestors first). If the profile
     *   is not given and cannot be determined, returns an empty array.
     */
    public function getAncestors($profile = NULL) {
      $ancestors = [];
  
      if (empty($profile)) {
        $profile = $this-&gt;installProfile ?: drupal_get_profile();
      }
      if (empty($profile)) {
        return $ancestors;
      }
  
      $extension = $this-&gt;get($profile);
  
      foreach ($extension-&gt;ancestors as $ancestor) {
        $ancestors[$ancestor] = $this-&gt;get($ancestor);
      }
      $ancestors[$profile] = $extension;
  
      return $ancestors;
    }
  
    /**
     * Returns all available profiles which are distributions.
     *
     * @return \Drupal\Core\Extension\Extension[]
     *   Processed extension objects, keyed by machine name.
     */
    public function listDistributions() {
      return array_filter($this-&gt;getList(), function (Extension $profile) {
        return !empty($profile-&gt;info['distribution']);
      });
    }
  
    /**
     * Select the install distribution from the list of profiles.
     *
     * If there are multiple profiles marked as distributions, select the first.
     * If there is an inherited profile marked as a distribution, select it over
     * its base profile.
     *
     * @param string[] $profiles
     *   List of profile names to search.
     *
     * @return string|null
     *   The selected distribution profile name, or NULL if none is found.
     */
    public function selectDistribution(array $profiles = NULL) {
      $distributions = $this-&gt;listDistributions();
  
      if ($profiles) {
        $distributions = array_intersect_key($distributions, array_flip($profiles));
      }
  
      // Remove any distributions which are extended by another one.
      foreach ($distributions as $profile_name =&gt; $profile) {
        if (!empty($profile-&gt;info['base profile'])) {
          $base_profile = $profile-&gt;info['base profile'];
          unset($distributions[$base_profile]);
        }
      }
  
      return key($distributions) ?: NULL;
    }
  
    /**
     * {@inheritdoc}
     */
    protected function doList() {
      $profiles = parent::doList();
  
      // Compute the ancestry of each profile before any further processing.
      foreach ($profiles as $profile) {
        // Maintain a list of profiles which depend on this one.
        $profile-&gt;children = [];
  
        // Maintain a list of profiles that this one depends on, in reverse
        // ancestral order (immediate parent first).
        $profile-&gt;ancestors = $this-&gt;computeAncestry($profiles, $profile);
  
        // Give the profile a heavy weight to ensure that its hooks run last.
        $profile-&gt;weight = count($profile-&gt;ancestors) + 1000;
      }
  
      // For each profile, merge in ancestors' module and theme lists.
      foreach ($profiles as $profile_name =&gt; $profile) {
        if (empty($profile-&gt;ancestors)) {
          continue;
        }
        // Reference the extension info here for readability.
        $info = &amp;$profile-&gt;info;
  
        // Add the parent profile as a hard dependency.
        $info['dependencies'][] = reset($profile-&gt;ancestors);
  
        // Add all themes and extensions listed by ancestors.
        foreach ($profile-&gt;ancestors as $ancestor) {
          $ancestor = $profiles[$ancestor];
  
          // Add the current profile as a child of the ancestor.
          $ancestor-&gt;children[] = $profile_name;
  
          // Inherit all of the ancestor's modules and themes except for the ones
          // in the 'exclude' list.
          $info['install'] = array_diff(array_merge($info['install'], $ancestor-&gt;info['install']), $info['exclude']);
          $info['themes'] = array_diff(array_merge($info['themes'], $ancestor-&gt;info['themes']), $info['exclude']);
        }
        $info['install'] = array_unique($info['install']);
        $info['themes'] = array_unique($info['themes']);
      }
      return $profiles;
    }
  
    /**
     * Computes and returns the ancestral lineage of a profile.
     *
     * @param \Drupal\Core\Extension\Extension[] $profiles
     *   All discovered profiles.
     * @param \Drupal\Core\Extension\Extension $profile
     *   The profile for which to compute the ancestry.
     *
     * @return string[]
     *   The names of the ancestors of the given profile, in order.
     */
    protected function computeAncestry(array $profiles, Extension $profile) {
      $ancestors = [];
  
      while (!empty($profile-&gt;info['base profile'])) {
        array_unshift($ancestors, $profile-&gt;info['base profile']);
        $profile = $profile-&gt;info['base profile'];
        $profile = $profiles[$profile];
      }
      return $ancestors;
    }
  </code></pre>
  
  <p>I'm looking for assistance on cleaning this up to get rid of the warnings. Previously these warnings weren't showing up. My colleague updated us from 8.6.16 to 8.7, but even when he was pushing the warnings were showing.</p>