PHP 8.3 Processes Diferently Than 7.4

From: Date: Fri, 04 Oct 2024 18:44:11 +0000
Subject: PHP 8.3 Processes Diferently Than 7.4
Groups: php.general 
Request: Send a blank email to php-general+get-328542@lists.php.net to get a copy of this message
I have a script with an include file that contains a function called 'get_show_list' that has a referenced array which is causing PHP to abort the script. The following used to work in 7.4: *** Code Snippet from the Include File *** $base_dir = "/home/tgvpadmin/data/shows"; $content_dir = "/home/tgvpadmin/content/programs"; $archive_dir = "/home/tgvpadmin/content/archives"; // Return list of sorted shows, taking definite articles into account function get_show_list () {   global $base_dir;   $base_dir_handle = @opendir ($base_dir);   if (!$base_dir_handle)
    die ("Couldn't open directory $base_dir");
  while (($filename = readdir ($base_dir_handle)) !== false) {
    if (($filename != ".") and ($filename != "..") and (is_dir ("$base_dir/$filename"))
     and ($showname_handle = @fopen ("$base_dir/$filename/showname", "r"))) {
      $shows[$filename] = trim (fgets ($showname_handle));
      fclose ($showname_handle);
    } // end if a dir with a showname file
  } // end traversal of directory   closedir ($base_dir_handle); // Copy to another array for sorting purposes   $sorted_shows = $shows; // Make all show names lowercase for sorting and searching   reset ($sorted_shows);   while (list ($key, $value) = each ($sorted_shows))
    $sorted_shows[$key] = strtolower ($sorted_shows[$key]);
// Strip off "the" and "la" etc.   reset ($sorted_shows);   while (list ($key, $value) = each ($sorted_shows)) {
    if (strpos ($value, " ")) {
      $space_pos = strpos ($value, " ");
      $first_word = substr ($value, 0, $space_pos);
      switch ($first_word) {
        case "the":
        case "a":
        case "an":
        case "la":
        case "el":
          $sorted_shows[$key] = substr ($value, $space_pos + 1);
          break;
      } // end switch on first word
    } // end if more than one word in a show title
  } // end while list of shows // Use asort to maintain keys   asort ($sorted_shows); // Generate sorted list with original show names   reset ($sorted_shows);   while (list ($key, $value) = each ($sorted_shows)) {
    $show_list[$key] = $shows[$key];
  } // end while list of shows   return $show_list; } // end get_show_list () *** End Code *** There's a lot more I omitted for brevity and that I don't think it's involved, but here's the error I get when I run the calling script: PHP Fatal error:  Uncaught Error: Call to undefined function each() in /home/tgvpadmin/domains/theglobalvoice.info/public_html/gallery.inc:35 Stack trace: #0 /home/tgvpadmin/domains/theglobalvoice.info/public_html/mail_gallery_updates.php(32): get_show_list() #1 {main}   thrown in /home/tgvpadmin/domains/theglobalvoice.info/public_html/gallery.inc on line 35 "each" is not a function. It's a list. What changed that affected the way this worked between 7.4 and 8.3? I looked through the manual sections on arrays and lists and didn't find anything that looked like it was the problem. TIA

« previous php.general (#328542) next »