You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PHP 8.5 array_column Deprecation warning: Using null as an array offset is deprecated, use an empty string instead #25144
Deprecated: Using null as an array offset is deprecated, use an empty string instead in /x/y/z/test.php on line 16
Array ( [Inco] => Array ( [a] => Blaa [b] => Inco ) [] => Array ( [a] => XXX [b] => ) )
But I expected this output instead:
Array ( [Inco] => Array ( [a] => Blaa [b] => Inco ) [] => Array ( [a] => XXX [b] => ) )
If the intention is to blow up at this point in future PHP versions then it's going to add a lot of maintenance dev and extra overhead to fix it. To what advantage ?
If I'm going to have to loop through the array checking for nulls each time then I may as well dispense with array_column completely and write my own function - which will be nowhere near as performant as the existing PHP function.
PHP Version
PHP 8.5.12 (cli) (built: Oct 21 2026 14:36:25) (NTS)
Copyright (c) The PHP Group
Built by Ubuntu
Zend Engine v4.5.12, Copyright (c) Zend Technologies
with Zend OPcache v8.5.12, Copyright (c), by Zend Technologies
2. This deprecation was intentionally introduced in 49e3956 as part of the PHP 8.5 deprecations. See the changes.
I'm aware of that.
The point I am making is: If the intention is to blow up at this point in future PHP versions, it means I'm going to have to loop through the array checking for nulls each time so I may as well dispense with array_column completely and write my own function - which will be nowhere near as performant as the existing PHP function.
What's your solution ?
Thank you
The deprecation is related to using null as an array key, not to array_column() itself. Since array_column() uses the values from the specified index column as keys in the resulting array, a null value in that column triggers the deprecation.
To avoid it, you would need to normalize the keys before using array_column(). I understand your concern about the additional iteration and performance overhead.
4. The deprecation is related to using null as an array key, not to array_column() itself. Since array_column() uses the values from the specified index column as keys in the resulting array, a null value in that column triggers the deprecation.
To avoid it, you would need to normalize the keys before using array_column(). I understand your concern about the additional iteration and performance overhead.
Thanks for your commentary. What's the point of using array_column if I'm going to have to iterate the array anyway to prevent it blowing up on nulls in future PHP versions ? I may as well just re-write array_column so it carries on working as it has for the past 13 years ? Is there any other solution ?
Ideally you array shouldn't even be containing such values if you are going to use array_column, one of the many static analysis tools out there can help you identify the root cause.
6. array_column already blows up if you have invalid types: https://3v4l.org/GZi8D#v
Ideally you array shouldn't even be containing such values if you are going to use array_column, one of the many static analysis tools out there can help you identify the root cause.
As such I'm marking this as Won't fix.
I know exactly why there are nulls in the data. It's not going away. Goodbye array_column :-(
10. Does that mean you want it to do:
$arr ??= [];
print_r(array_combine(array_map(fn($b) => $b ?? '', array_column($arr, 'b')), $arr));
Many thanks for presenting a possible alternative.
It does use 3 functions to do the same thing as per array_column pre PHP 8.5 but with complex and pretty much unreadable code.
I'm wondering how it's going to be any more performant than writing a new safe_array_column function which iterates the array in a loop ?
Activity
arshidkv12 commentedon Nov 2, 2026
This deprecation was intentionally introduced in 49e3956 as part of the PHP 8.5 deprecations. See the changes.
clarumedia commentedon Nov 2, 2026
I'm aware of that.
The point I am making is: If the intention is to blow up at this point in future PHP versions, it means I'm going to have to loop through the array checking for nulls each time so I may as well dispense with array_column completely and write my own function - which will be nowhere near as performant as the existing PHP function.
What's your solution ?
Thank you
arshidkv12 commentedon Nov 2, 2026
The deprecation is related to using null as an array key, not to
array_column()itself. Sincearray_column()uses the values from the specified index column as keys in the resulting array, a null value in that column triggers the deprecation.To avoid it, you would need to normalize the keys before using
array_column(). I understand your concern about the additional iteration and performance overhead.clarumedia commentedon Nov 2, 2026
Thanks for your commentary. What's the point of using array_column if I'm going to have to iterate the array anyway to prevent it blowing up on nulls in future PHP versions ? I may as well just re-write array_column so it carries on working as it has for the past 13 years ? Is there any other solution ?
Girgias commentedon Nov 2, 2026
array_columnalready blows up if you have invalid types: https://3v4l.org/GZi8D#vIdeally you array shouldn't even be containing such values if you are going to use array_column, one of the many static analysis tools out there can help you identify the root cause.
As such I'm marking this as Won't fix.
clarumedia commentedon Nov 2, 2026
I know exactly why there are nulls in the data. It's not going away. Goodbye array_column :-(
MorganLOCode commentedon Nov 2, 2026
Does that mean you want it to do:
clarumedia commentedon Nov 3, 2026
Many thanks for presenting a possible alternative.
It does use 3 functions to do the same thing as per array_column pre PHP 8.5 but with complex and pretty much unreadable code.
I'm wondering how it's going to be any more performant than writing a new safe_array_column function which iterates the array in a loop ?
I never knew that array_column had support for objects as well as per the source code ?
https://github.com/php/php-src/blob/master/ext/standard/array.c#L4662