Fixed array_column vs XenForo_Application::arrayColumn behavioural differences depending on php version

Xon

Well-known member
Affected version
1.5.14, 2.0 DP10
When array_column doesn't exist (ie php version <5.5), XenForo_Application::arrayColumn implements fallback code, but the $row isn't checked if it is an array.

As such, this code behaves differently in php 5.4 vs php 5.5;
Code:
$arr = XenForo_Application::arrayColumn(array(1,2,3,4,5), 'id');

In php 5.4 (or older), it will throw an error;
Server Error
array_key_exists() expects parameter 2 to be array, integer given

  1. XenForo_Application::handlePhpError()
  2. array_key_exists() in XenForo/Application.php at line 1242

In php 5.5 and above, it returns and empty array.

Note; this also applies to the XF2 \XF\Util\Arr::arrayColumn which is a copy & paste of the same code.
 
This is fixed now. There was also another situation that was inconsistent, also relating to passing a non-multi-dimensional array.
 
Top Bottom