PHP-EACH-001
each($array)
each() / create_function() / ereg / split
These PHP functions were removed long before Joomla 6. Joomla 4 already needs PHP 7.2+; Joomla 5 needs 8.1; Joomla 6 needs 8.3. Old extension code still contains them.
each($array) → foreach / closures / preg_*
What you will see
- Call to undefined function each()
- Call to undefined function create_function()
- Call to undefined function ereg()
- Call to undefined function split()
- Call to undefined function get_magic_quotes_gpc()
Symptoms people search
php 8 fatal in a helper file
Replace this code
Swap each($array) for foreach / closures / preg_*.
Joomla 3
Remove or stop calling this
while (list($k, $v) = each($rows)) { }
$fn = create_function('$a', 'return $a;');Joomla 4 / 6
Use this instead
foreach ($rows as $k => $v) { }
$fn = static fn ($a) => $a;How to fix it
- 1each() → foreach.
- 2create_function() → a closure.
- 3ereg/split → preg_match / explode / preg_split.
- 4get_magic_quotes_gpc() → delete; filter input instead.
Also known as
each · create_function · ereg · split · magic_quotes
Related issues
- Joomla 3 → 4Joomla API
JError / JException
JError::raiseError() → throw new RuntimeException() / try-catch
- Joomla 3 → 4PHP
jimport() autoloader calls
jimport('joomla.filesystem.file') → use Joomla\CMS\Filesystem\File;
- Joomla 3 → 4PHP
DS path constant
DS → DIRECTORY_SEPARATOR or /
- Joomla 3 → 4PHP
JPATH_PLATFORM
JPATH_PLATFORM → Do not use — autoload instead
- Joomla 3 → 4PHP
mysql_* PHP functions
mysql_query() → Joomla DatabaseInterface / mysqli / PDO
- Joomla 4 → 5PHP
Dynamic PHP properties (PHP 8.2+)
$this->foo = 1 on an untyped class → Declare the property or use AllowDynamicProperties