In a production environment that uses the Yii1 framework and PHP 5.6.40, the array_column function is returning an empty array.
The array is a list of CActiveRecords from another CActiveRecord's HAS_MANY relation. On my local machine (PHP 7.1.23), the array_column function works as expected. Unless I misunderstand, the documentation says that array_column is available in PHP 5.6.40.
/**
* This is the model class for table 'my_active_record'.
*
* The following are the available columns in table 'my_active_record':
* @property integer $id
*
* The following are the available model relations:
* @property RelatedActiveRecord[] $relatedActiveRecords
*/
class MyActiveRecord extends CActiveRecord
{
public function relations()
{
return array(
'relatedActiveRecords' => array(self::HAS_MANY, 'related_active_records', 'my_active_record_id')
);
}
}
/**
* This is the model class for table 'related_active_record'.
*
* The following are the available columns in table 'related_active_record':
* @property integer $id
* @property integer $my_active_record_id
*
* The following are the available model relations:
* @property MyActiveRecord $myActiveRecord
*/
class MyActiveRecord extends CActiveRecord
{
public function relations()
{
return array(
'myActiveRecord' => array(self::BELONGS_TO, 'my_active_record', 'my_active_record_id')
);
}
}
$myActiveRecord = new MyActiveRecord();
print_r(array_column($myActiveRecord->relatedActiveRecords, 'id'));
Expected results: Array ( [0] => 1 [1] => 2 [2] => 3 )
Actual results: Array ( ).