phpsmtpdrupal-7eachdrupal-modules

Solution for removed each function in smtp module of drupal 7 on php 8 servers


I noticed an error in smtp.transport.inc of the drupal module smtp 7.x-1.7 because of the in php 7.2 deprecated and in php 8 removed function "each()".

Unfortunatelay a customers drupal 7 project runs on a server which the provider upgraded to php 8. I think the maintainers of the smtp module didn't suppose anybody to use this combination of drupal and php version. The code with each() is

  1. while (list(, $line) = @each($lines)) { in line 393

and

  1. while (list(, $line_out) = @each($lines_out)) { in line 423.

Solution

  • Because I already developed a solution I will answer my question by myself:

    I had to rewrite the lines using each()

    1. while (list(, $line) = @each($lines)) { in line 393

    and

    1. while (list(, $line_out) = @each($lines_out)) { in line 423.

    My solution was to replace the while ... each loops with a for loop. So I changed

    1. while (list(, $line) = @each($lines)) {

    into

    for ($i = 0; $i < count($lines); $i++) { $line = $lines[$i];

    and the second inner loop

    1. while (list(, $line_out) = @each($lines_out)) {

    into

    for ($ii = 0; $ii < count($lines_out); $ii++) { $line_out = $lines_out[$ii];

    So from now on it works for me. I hope I could help those who are in the same situation.