PHP VERSION: 8.2.18

changed_functions_array_column.php

<?php
// array_column() now accepts an array of objects

class Foo
{
    public 
$col1 1;
    public 
$col2 'TWO';
    protected 
$col3 3;
    protected 
$col4 'FOUR';
    public function 
__get($var)
    {
        return 
$this->$var;
    }
    
// NOTE: if __isset() is not defined, __get() will not work with array_column()
    
public function __isset($var)
    {
        return isset(
$this->$var);
    }   
}

$array[] = new Foo();
$array[] = new Foo();
$array[] = new Foo();

var_dump(array_column($array'col1'));
var_dump(array_column($array'col2'));
var_dump(array_column($array'col3'));
var_dump(array_column($array'col4'));


Output


array(3) {
  [0]=>
  int(1)
  [1]=>
  int(1)
  [2]=>
  int(1)
}
array(3) {
  [0]=>
  string(3) "TWO"
  [1]=>
  string(3) "TWO"
  [2]=>
  string(3) "TWO"
}
array(3) {
  [0]=>
  int(3)
  [1]=>
  int(3)
  [2]=>
  int(3)
}
array(3) {
  [0]=>
  string(4) "FOUR"
  [1]=>
  string(4) "FOUR"
  [2]=>
  string(4) "FOUR"
}
SOURCE CODE