<?php
class User
{
public $username;
public function __construct(string $username)
{
$this->username = $username;
}
}
$users = [
new User('user 1'),
new User('user 2'),
new User('user 3'),
];
print_r(array_column($users, 'username'));
Array
(
[0] => user 1
[1] => user 2
[2] => user 3
)
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Array
(
[0] => user 1
[1] => user 2
[2] => user 3
)
Output for 5.6.0 - 5.6.40
Catchable fatal error: Argument 1 passed to User::__construct() must be an instance of string, string given, called in /in/YG4rM on line 14 and defined in /in/YG4rM on line 7
Process exited with code 255.