PHP Classes

Error: Call to undefined function each()

Recommend this page to a friend!

      Receive Mail  >  All threads  >  Error: Call to undefined function each()  >  (Un) Subscribe thread alerts  
Subject:Error: Call to undefined function each()
Summary:When trying out the Example.php, first record show ok
Messages:2
Author:Palle Gude
Date:2023-08-31 12:36:31
 

  1. Error: Call to undefined function each()   Reply   Report abuse  
Picture of Palle Gude Palle Gude - 2023-08-31 12:36:31
I am trying with Example and get one record shown, then an error:

Fatal error: Uncaught Error: Call to undefined function each() in /customers/1/7/5/gude.uk/httpd.www/support/receivemail.class.php:280 Stack trace: #0 /customers/1/7/5/gude.uk/httpd.www/support/receivemail.class.php(115): ReceiveMail->get_part(Object(IMAP\Connection), 1556, 'TEXT/HTML') #1 /customers/1/7/5/gude.uk/httpd.www/support/example.php(47): ReceiveMail->get_email_body(1556) #2 {main} thrown in /customers/1/7/5/gude.uk/httpd.www/support/receivemail.class.php on line 280

  2. Re: Error: Call to undefined function each()   Reply   Report abuse  
Picture of Palle Gude Palle Gude - 2023-08-31 15:19:59 - In reply to message 1 from Palle Gude
I asked Bard and it said, try this:

$array = [1, 2, 3, 4, 5];

// Old code
while (list($key, $value) = each($array)) {
echo "$key $value\n";
}

// New code
foreach ($array as $key => $value) {
echo "$key $value\n";
}

And now i get output like this:

Array
(
[datetime] => 2023-08-24 14:06:34
[from] => support@brooksdale.co.uk
[fromName] => Brooksdale
[replyTo] => support@brooksdale.co.uk
[replyToName] => Brooksdale
[subject] => Welcome to Brooksdale
[to] => user@email.uk
[full_header] => O:8:"stdClass":23:{s:4:"date";s:37:"Thu, 24 Aug )